Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Conversation

cyanglaz
Copy link
Contributor

@cyanglaz cyanglaz commented Mar 20, 2019

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 no invokeMethod 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 and sensor.

flutter/flutter#26431

// 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>[
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
final dynamic r = await _channel.invokeMethod<dynamic>('Alarm.periodic', <dynamic>[
return _channel.invokeMethod<bool>('Alarm.periodic', <dynamic>[

// 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>>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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

@jonahwilliams
Copy link
Contributor

There are many places where you are using <dynamic> and then doing a manual cast - those should be refactored to use <correctType>

@cyanglaz
Copy link
Contributor Author

Closing the PR now for refactoring using invokeListMethod and invokeMapMethod

@cyanglaz cyanglaz closed this Mar 20, 2019
@cyanglaz
Copy link
Contributor Author

Updated invokeMethod and invokeMethod to using invokeListMethod and invokeMapMethod. Reopen the PR.

@cyanglaz cyanglaz reopened this Mar 20, 2019
/// @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 {
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

@jonahwilliams jonahwilliams left a 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

Copy link
Contributor

@amirh amirh left a 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.


Copy link
Contributor

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
Copy link
Contributor

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');
Copy link
Contributor

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>(
Copy link
Contributor

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'],
Copy link
Contributor

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>(
Copy link
Contributor

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>:

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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got so far

Copy link
Contributor

@bparrishMines bparrishMines left a 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>(
Copy link
Contributor

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>(
Copy link
Contributor

@bparrishMines bparrishMines Mar 25, 2019

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.

@cyanglaz
Copy link
Contributor Author

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.

@cyanglaz cyanglaz closed this Mar 25, 2019
julianscheel pushed a commit to jusst-engineering/plugins that referenced this pull request Mar 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants