-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial Commit for PlaformChannel Sample App #453
Initial Commit for PlaformChannel Sample App #453
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AyushBherwani1998, this is a great start. I've added a lot of comments (and, I should warn you, there's probably a few more to come 😄 ), but that's mostly just because this is the first PR and an especially big one. Once you get going on this app, we'll know each other better and the process will speed up.
Let me know what you think and when you're ready for another look!
@@ -0,0 +1,3 @@ | |||
# Platform Channel Samples |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file needs to get bigger and more detailed. Take a look at the README in jsonexample for a model:
https://github.com/flutter/samples/blob/master/jsonexample/README.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking to add a detailed README after the project. As of now, I have improved it taking the base from other samples in the repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new stuff looks great. The only additional suggestion I have is to add a line just before "Goals" that says "This sample is currently being built. Not all platforms and functionality are in place."
- unnecessary_brace_in_string_interps | ||
- unnecessary_getters_setters | ||
- unnecessary_new | ||
- unnecessary_statements |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Throw a newline on this.
@@ -0,0 +1,7 @@ | |||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |||
package="com.example.platform_channels"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We generally use "dev.flutter" or "dev.flutter.example" as the org. You should be able to run:
flutter create --org="dev.flutter" .
in the project directory to change it.
platform_channels/lib/main.dart
Outdated
} | ||
|
||
// List of all the demos with their titles and routes. | ||
final demoList = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically we'd make a simple data class for this rather than using maps, so you'd have List<DemoData>
rather than List<Map<String, String>>
.
platform_channels/lib/main.dart
Outdated
appBar: AppBar( | ||
title: Text('Platform Channel Sample'), | ||
), | ||
body: SingleChildScrollView( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you consider using a ListView here? While it's unlikely to matter in this case, ListView is significantly more performant than a scrolling Column.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did consider using a ListView
, but I think we won't have many DemoTile's on the screen. I'm using SingleChildScrollView
just to be on safer side in case if user is testing in small device.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed offline, and we decided to go with a ListView.
@override | ||
void initState() { | ||
super.initState(); | ||
count = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also just initialize count to 0 right in its declaration and get ride of this override.
title: const Text('MethodChannel Demo'), | ||
), | ||
floatingActionButton: Row( | ||
mainAxisAlignment: MainAxisAlignment.start, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Start is the default, so you can actually leave this out.
appBar: AppBar( | ||
title: const Text('MethodChannel Demo'), | ||
), | ||
floatingActionButton: Row( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that if one is going to have two FABs, they should be a in a Column. At least that's the example they show on the Material site:
https://material.io/components/buttons-floating-action-button
I was expecting comments for the feedback and reviews to help me better understand how the samples are maintained 😄 . I'll push the changes soon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really close!
@@ -0,0 +1,3 @@ | |||
# Platform Channel Samples |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new stuff looks great. The only additional suggestion I have is to add a line just before "Goals" that says "This sample is currently being built. Not all platforms and functionality are in place."
platform_channels/README.md
Outdated
## Goals | ||
|
||
* Demonstrate how to use `MethodChannel` to invoke platform methods. | ||
* Demonstrate how to use `EventChannel` to listen continous value changes across the platforms. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "to listen to continuous value changes from the platform."
|
||
if (call.argument<Int>("count") != null) { | ||
count = call.argument<Int>("count")!! | ||
val count: Int? = call.argument<Int>("count") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great. Much tighter code.
platform_channels/lib/main.dart
Outdated
appBar: AppBar( | ||
title: Text('Platform Channel Sample'), | ||
), | ||
body: SingleChildScrollView( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed offline, and we decided to go with a ListView.
/// It has two [FloatingActionButton]s and a [Text] widget to display the value of | ||
/// [count]. | ||
/// It has two [FloatingActionButton]s to increment and decrement the value of | ||
/// [count], and a [Text] widget to display the value it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "...to display its value."
FloatingActionButton( | ||
heroTag: 'addition', | ||
child: Icon(Icons.add), | ||
floatingActionButton: Builder( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice refactor. Builder has saved me a lot of keys. :)
FloatingActionButton( | ||
heroTag: 'subtract', | ||
child: Icon(Icons.remove), | ||
// Whenever users presses the FloatingActionButton, it invokes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "...users press the..."
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:platform_channels/src/method_channel_demo.dart'; | ||
|
||
void main() { | ||
TestWidgetsFlutterBinding.ensureInitialized(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be necessary. Try taking it out and see if everything still works. :)
onPressed: () { | ||
Counter.increment(counterValue: count).then((value) { | ||
setState(() => count = value); | ||
}).catchError((dynamic error) { | ||
showErrorMessage( | ||
context, | ||
error.message as String, | ||
); | ||
}); | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe I had a comment in this section earlier, but just in case: typically I would expect to see an async method here. Generally we recommend using async/await over the Futures API whenever possible.
The logic can all stay the same; it's just a syntactical change:
onPressed: () async {
try {
final value = await Counter.increment(counterValue: count);
setState(() => count = value);
} catch (error) {
showErrorMessage(
context,
error.message as String,
);
}
},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed it in the previous commit after doing the changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM other than the one suggestion about shuffling some test code around. Let me know what you want to do there, and then we can merge this.
Description
GIF
@RedBrogdon @domesticmouse I have few doubts regarding the current commit. I'll state them below
Currently, for testing the functionality of the counter, I need to write an integration test. Should I write an integration test or just unit test which Mocks the increment and decrement methods using
setMockMethodCallHandler
? I can also use theprovider
package since my logic is already separated out and in the test, I can create a Mock.Currently, I have separated the logic for the MethodChannel and method calls in the class named
Counter
. Is that how we are looking to implement the demos? If yes, then is there any project structure I should follow?