invokeMethod method

Future invokeMethod (String method, [ arguments ])

Invokes a method on this channel with the specified arguments.

The static type of arguments is dynamic, but only values supported by the codec of this channel can be used. The same applies to the returned result. The values supported by the default codec and their platform-specific counterparts are documented with StandardMessageCodec.

Returns a Future which completes to one of the following:

  • a result (possibly null), on successful invocation;
  • a PlatformException, if the invocation failed in the platform plugin;
  • a MissingPluginException, if the method has not been implemented by a platform plugin.

See also:


Future<dynamic> invokeMethod(String method, [dynamic arguments]) async {
  assert(method != null);
  final dynamic result = await BinaryMessages.send(
    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);