-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Closed
Labels
frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.
Description
i.e. instead of:
flutter/packages/flutter/lib/src/services/platform_channel.dart
Lines 271 to 280 in 0a4c116
| Future<dynamic> invokeMethod(String method, [dynamic arguments]) async { | |
| assert(method != null); | |
| final dynamic result = await BinaryMessages.send( | |
| name, | |
| codec.encodeMethodCall(new MethodCall(method, arguments)), | |
| ); | |
| if (result == null) | |
| throw new MissingPluginException('No implementation found for method $method on channel $name'); | |
| return codec.decodeEnvelope(result); | |
| } |
Something like:
Future<T> invokeMethod<T>(String method, [dynamic arguments]) async {
...
return result as T;
}There are a lot of runtime errors being reported by errors:
dart-lang/pub-dev#1263 (comment)
The advantage here is that T can be filled in automatically in most cases:
// Automatically infers invokeMethod<bool>!
Future<bool> isEnabled() => invokeMethod('isEnabled');... and I imagine this would be a non-breaking change, as a plus! This won't work for more complex types, like List<String>, but maybe that's either OK or some variants of invokeMethod could be added to help, for example:
Future<List<T>> invokeMethodList<T>(...)Future<Map<K, V>> invokeMethodMap<K, V>(...)
jonahwilliams, isoos, thosakwe, marnberg, lucaslcode and 1 more
Metadata
Metadata
Assignees
Labels
frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.