-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Template type invokemethod #1365
Conversation
// https://github.com/flutter/flutter/issues/26431 | ||
// ignore: strong_mode_implicit_dynamic_method | ||
final dynamic r = await _channel.invokeMethod('Alarm.periodic', <dynamic>[ | ||
final dynamic r = await _channel.invokeMethod<dynamic>('Alarm.periodic', <dynamic>[ |
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.
final dynamic r = await _channel.invokeMethod<dynamic>('Alarm.periodic', <dynamic>[ | |
return _channel.invokeMethod<bool>('Alarm.periodic', <dynamic>[ |
Co-Authored-By: cyanglaz <[email protected]>
packages/camera/lib/camera.dart
Outdated
// https://github.com/flutter/flutter/issues/26431 | ||
// ignore: strong_mode_implicit_dynamic_method | ||
final Map<dynamic, dynamic> reply = await _channel.invokeMethod( | ||
final Map<dynamic, dynamic> reply = await _channel.invokeMethod<Map<dynamic, dynamic>>( |
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.
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.
cool, going to do a massive change on all the invokeMethod that has map type
Co-Authored-By: cyanglaz <[email protected]>
Co-Authored-By: cyanglaz <[email protected]>
There are many places where you are using |
Closing the PR now for refactoring using invokeListMethod and invokeMapMethod |
…ins into template_type_invokemethod
Updated invokeMethod and invokeMethod to using invokeListMethod and invokeMapMethod. Reopen the PR. |
/// @param functionName The name of the callable function being triggered. | ||
/// @param parameters Parameters to be passed to the callable function. | ||
Future<dynamic> call( | ||
{@required String functionName, Map<String, dynamic> parameters}) async { |
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 don't know what this is supposed to return, but you could add a similar feature to the invokeMethod to allow users to use inference instead of casting:
Future<T> call( Future<dynamic> call<T>(
{@required String functionName, Map<String, dynamic> parameters}) async {
Where if T
isn't specified it defaults to dynamic. Example:
final bool x = cloudFunctions.call(functionName: 'hello'); // <T> inferred as bool
final y = cloudFunctions.call<String>(functionName: 'bar'); // <T> specified 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.
SG, I think we can follow this up in a different PR.
Also, by looking at the implementation, this method should return Future<Map<String, dynamic>>, however it would be breaking change since call is a public method. I would avoid that in this PR. And after this is merged and if we think it is necessary to break, then we can create another PR to fix this.
There are other places that has public API returning which I am also avoiding in this PR.
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 for invokeMethod, invokeMapMethod
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.
Still reviewing, sending so I know how far I went so far, will let you know when I got all the way through
* Bump the minimum flutter version to 1.2.0. | ||
* Add Template type parameter to `invokeMethod` calls. | ||
|
||
|
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: extra empty line here
@@ -1,7 +1,7 @@ | |||
## 0.9.7 | |||
## 0.9.6+1 |
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 should be 7+1
// https://github.com/flutter/flutter/issues/26431 | ||
// ignore: strong_mode_implicit_dynamic_method | ||
_channel.invokeMethod('AlarmService.initialized'); | ||
_channel.invokeMethod<void>('AlarmService.initialized'); |
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 should be bool following the fix in #1384
// https://github.com/flutter/flutter/issues/26431 | ||
// ignore: strong_mode_implicit_dynamic_method | ||
: _handle = Firestore.channel.invokeMethod( | ||
: _handle = Firestore.channel.invokeMethod<dynamic>( |
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.
Isn't the return type for this a int?
isPhysicalDevice: map['isPhysicalDevice'], | ||
androidId: map['androidId'], | ||
version: AndroidBuildVersion._fromMap(message['version']), | ||
board: message['board'], |
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: probably better to keep the rename for a different PR so the blame lines make sense
// https://github.com/flutter/flutter/issues/26431 | ||
// ignore: strong_mode_implicit_dynamic_method | ||
return await FirebaseAuth.channel.invokeMethod( | ||
return await FirebaseAuth.channel.invokeMethod<void>( |
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 seems to return a Map<String, Object>
:
Line 455 in 0403387
currentUser.unlink(provider).addOnCompleteListener(new SignInCompleteListener(result)); |
environment: | ||
sdk: ">=2.0.0-dev.28.0 <3.0.0" | ||
flutter: ">=0.1.4 <2.0.0" | ||
flutter: ">=1.2.0 <2.0.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.
I got so far
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 PR may be better separated into a PR for each plugin. The use of invokeListMethod and invokeMapMethod seem to assume that the result won't be null
and attempts to cast()
. If this is true, this PR could lead to a lot of unintended crashes and breaking changes if a user was anticipating a possible null value.
However, they could be changed to only cast if result isn't null. @jonahwilliams.
// https://github.com/flutter/flutter/issues/26431 | ||
// ignore: strong_mode_implicit_dynamic_method | ||
final List<dynamic> providers = await channel.invokeMethod( | ||
return await channel.invokeListMethod<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.
Wouldn't invokeListMethod crash when result.cast<T>();
is called and providers == null
.
This makes me wonder if we should use invokeListMethod
and invokeMapMethod
in this PR because in some cases we want to return null values.
// ignore: strong_mode_implicit_dynamic_method | ||
await channel.invokeMethod('FirebaseDynamicLinks#retrieveDynamicLink'); | ||
final Map<String, dynamic> linkData = | ||
await channel.invokeMapMethod<String, dynamic>( |
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 may crash due to the cast in the method invokeMapMethod
call as well. linkData
could equal null
.
I am going to close this one and create different PRs for each plugin. I feel like much safer that way and easier to review. |
Bump min flutter version to 1.2.0 for most plugins.
Add template type parameter for
invokeMethod
calls.Updated invokeMethod and invokeMethod to using invokeListMethod and invokeMapMethod. Reopen the PR.
Anything that will change the type of a public API should not be included in this PR.
Sensor
plugin has not been changed since noinvokeMethod
is called in the plugin.The plugin version of
in app purchase
has not be updated because it is still under development.Need to publish all plugins after this PR is merged, except
in_app_purchase
andsensor
.flutter/flutter#26431