setMethodCallHandler method

void setMethodCallHandler (Future handler(MethodCall call))

Sets a callback for receiving method calls on this channel.

The given callback will replace the currently registered callback for this channel, if any. To remove the handler, pass null as the handler argument.

If the future returned by the handler completes with a result, that value is sent back to the platform plugin caller wrapped in a success envelope as defined by the codec of this channel. If the future completes with a PlatformException, the fields of that exception will be used to populate an error envelope which is sent back instead. If the future completes with a MissingPluginException, an empty reply is sent similarly to what happens if no method call handler has been set. Any other exception results in an error envelope being sent.


void setMethodCallHandler(Future<dynamic> handler(MethodCall call)) {
    handler == null ? null : (ByteData message) => _handleAsMethodCall(message, handler),