Skip to content

Conversation

@jonahwilliams
Copy link
Contributor

@jonahwilliams jonahwilliams commented Jan 9, 2019

Fixes #17333

This adds a type parameter T to the invokeMethod method, which allows it to automatically return a properly typed Future instead of requiring a manual cast. Also adds invokeListMethod and invokeMapMethod utilities for Lists and Maps, respectively. Due to the reified nature of Dart generics, it is not possible to cast a Future, List, or Map without creating a new wrapper.

Before:

// API returns a bool
final result = channel.invokeMethod('example');
acceptsFutureBool(result); // Might crash, Future<dynamic> cannot be assigned to Future<bool>.

After:

final result = channel.invokeMethod<bool>('example');
// or
final bool result = channel.invokeMethod('example'); // T is inferred
acceptsFutureBool(result); // yay!

Additionally, I've added two utility methods to help with returning Maps and List (which have similar issues):

Before:

// Api returns a Map<String, String>, but actually it is Map<dynamic, dynamic>
final Map<String, String> result = await channel.invokeMethod('example'); // Map<dynamic, dynamic> cannot be assigned to Map<String, String>
final Map<String, String> result = await channel.invokeMethod('example').cast<String, String>();

After:

final result = await channel.invokeMapMethod<String, String>('example');
// or
final Map<String, String> result = await channel.invokeMapMethod('example'); // T is inferred.

@jonahwilliams
Copy link
Contributor Author

I guess @optionalTypeArguments isnt that optional

@Hixie
Copy link
Contributor

Hixie commented Jan 9, 2019

LGTM modulo comments (in particular, I don't think we should replace the awaits for void into returns)

@zoechi zoechi added framework flutter/packages/flutter repository. See also f: labels. plugin c: contributor-productivity Team-specific productivity, code health, technical debt. labels Jan 10, 2019
@jonahwilliams jonahwilliams merged commit 83af6f4 into flutter:master Jan 10, 2019
@jonahwilliams jonahwilliams deleted the invokeTyped branch January 10, 2019 21:21
jonahwilliams pushed a commit to jonahwilliams/flutter that referenced this pull request Jan 11, 2019
@jonahwilliams jonahwilliams mentioned this pull request Jan 11, 2019
amirh added a commit to amirh/plugins that referenced this pull request Jan 11, 2019
flutter/flutter#26303 added a template argument to `invokeMethod`, which triggers the `strong_mode_implicit_dynamic_method` analyzer warning in many call sites in the plugins repo.

We should add the type parameter to all these call sites, but we can only do that after bumping the Flutter dependency constraint which we will only do once the `invokeMethod` change makes it to the stable release.

For now we're suppressing the warning in all call sites (we're not disabling the lint wholesale as we still want it for the rest of the code)

See: flutter/flutter#26431
amirh added a commit to amirh/plugins that referenced this pull request Jan 11, 2019
flutter/flutter#26303 added a template argument to `invokeMethod`, which triggers the `strong_mode_implicit_dynamic_method` analyzer warning in many call sites in the plugins repo.

We should add the type parameter to all these call sites, but we can only do that after bumping the Flutter dependency constraint which we will only do once the `invokeMethod` change makes it to the stable release.

For now we're suppressing the warning in all call sites (we're not disabling the lint wholesale as we still want it for the rest of the code)

See: flutter/flutter#26431
amirh added a commit to flutter/plugins that referenced this pull request Jan 12, 2019
…s. (#1065)

flutter/flutter#26303 added a template argument to `invokeMethod`, which triggers the `strong_mode_implicit_dynamic_method` analyzer warning in many call sites in the plugins repo.

We should add the type parameter to all these call sites, but we can only do that after bumping the Flutter dependency constraint which we will only do once the `invokeMethod` change makes it to the stable release.

For now we're suppressing the warning in all call sites (we're not disabling the lint wholesale as we still want it for the rest of the code)

See: flutter/flutter#26431
kangwang1988 pushed a commit to XianyuTech/flutter that referenced this pull request Feb 12, 2019
andreidiaconu pushed a commit to andreidiaconu/plugins that referenced this pull request Feb 17, 2019
…s. (flutter#1065)

flutter/flutter#26303 added a template argument to `invokeMethod`, which triggers the `strong_mode_implicit_dynamic_method` analyzer warning in many call sites in the plugins repo.

We should add the type parameter to all these call sites, but we can only do that after bumping the Flutter dependency constraint which we will only do once the `invokeMethod` change makes it to the stable release.

For now we're suppressing the warning in all call sites (we're not disabling the lint wholesale as we still want it for the rest of the code)

See: flutter/flutter#26431
collinjackson pushed a commit to collinjackson/flutterfire-old2 that referenced this pull request Jun 24, 2019
…s. (#1065)

flutter/flutter#26303 added a template argument to `invokeMethod`, which triggers the `strong_mode_implicit_dynamic_method` analyzer warning in many call sites in the plugins repo.

We should add the type parameter to all these call sites, but we can only do that after bumping the Flutter dependency constraint which we will only do once the `invokeMethod` change makes it to the stable release.

For now we're suppressing the warning in all call sites (we're not disabling the lint wholesale as we still want it for the rest of the code)

See: flutter/flutter#26431
collinjackson pushed a commit to firebase/flutterfire that referenced this pull request Aug 14, 2019
…s. (#1065)

flutter/flutter#26303 added a template argument to `invokeMethod`, which triggers the `strong_mode_implicit_dynamic_method` analyzer warning in many call sites in the plugins repo.

We should add the type parameter to all these call sites, but we can only do that after bumping the Flutter dependency constraint which we will only do once the `invokeMethod` change makes it to the stable release.

For now we're suppressing the warning in all call sites (we're not disabling the lint wholesale as we still want it for the rest of the code)

See: flutter/flutter#26431
g123k pushed a commit to g123k/flutter_android_intent_with_parts that referenced this pull request Sep 4, 2019
…s. (#1065)

flutter/flutter#26303 added a template argument to `invokeMethod`, which triggers the `strong_mode_implicit_dynamic_method` analyzer warning in many call sites in the plugins repo.

We should add the type parameter to all these call sites, but we can only do that after bumping the Flutter dependency constraint which we will only do once the `invokeMethod` change makes it to the stable release.

For now we're suppressing the warning in all call sites (we're not disabling the lint wholesale as we still want it for the rest of the code)

See: flutter/flutter#26431
Akachu pushed a commit to Akachu/firebase_auth that referenced this pull request Sep 16, 2019
…s. (firebase#1065)

flutter/flutter#26303 added a template argument to `invokeMethod`, which triggers the `strong_mode_implicit_dynamic_method` analyzer warning in many call sites in the plugins repo.

We should add the type parameter to all these call sites, but we can only do that after bumping the Flutter dependency constraint which we will only do once the `invokeMethod` change makes it to the stable release.

For now we're suppressing the warning in all call sites (we're not disabling the lint wholesale as we still want it for the rest of the code)

See: flutter/flutter#26431
ryanheise pushed a commit to ryanheise/background_video_player that referenced this pull request Sep 29, 2019
…s. (#1065)

flutter/flutter#26303 added a template argument to `invokeMethod`, which triggers the `strong_mode_implicit_dynamic_method` analyzer warning in many call sites in the plugins repo.

We should add the type parameter to all these call sites, but we can only do that after bumping the Flutter dependency constraint which we will only do once the `invokeMethod` change makes it to the stable release.

For now we're suppressing the warning in all call sites (we're not disabling the lint wholesale as we still want it for the rest of the code)

See: flutter/flutter#26431
nksteven pushed a commit to nksteven/ntf-firebase_messaging that referenced this pull request Apr 8, 2020
…s. (#1065)

flutter/flutter#26303 added a template argument to `invokeMethod`, which triggers the `strong_mode_implicit_dynamic_method` analyzer warning in many call sites in the plugins repo.

We should add the type parameter to all these call sites, but we can only do that after bumping the Flutter dependency constraint which we will only do once the `invokeMethod` change makes it to the stable release.

For now we're suppressing the warning in all call sites (we're not disabling the lint wholesale as we still want it for the rest of the code)

See: flutter/flutter#26431
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

c: contributor-productivity Team-specific productivity, code health, technical debt. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a type argument <T> to invokeMethod

4 participants