-
Notifications
You must be signed in to change notification settings - Fork 30.2k
Add default methodCallHandler to MethodChannel's const constructor #34429
Copy link
Copy link
Closed
Labels
c: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.
Description
When a project with a plugin is beign created, the sample plugin class consists of:
// the platform channel itself
static const MethodChannel _channel = const MethodChannel('channel_name');
// methods that call platform
static ReturnType methodName(/*arguments, if any*/) { /*code that calls platform*/ }I would like to set a method call handler on _channel, but since it is static const I currently have no means of doing that. The solution I am using looks as follows:
static final MethodChannel _channel = getPluginChannel();
static MethodChannel _getPluginChannel()
{
final MethodChannel resultChannel = MethodChannel('channel_name');
resultChannel.setMethodCallHandler((MethodCall call) {
/*code*/
});
return resultChannel;
}The drawback here is that the _channel variable is not const and there is no way to make it const.
Is it possible to add Future<dynamic> handler(MethodCall call) optional argument to the const constructor of the MethodChannel class?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
c: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.