setMockMethodCallHandler method

void setMockMethodCallHandler (Future handler(MethodCall call))

Sets a mock callback for intercepting method invocations on this channel.

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

Later calls to invokeMethod will result in a successful result, a PlatformException or a MissingPluginException, determined by how the future returned by the mock callback completes. The codec of this channel is used to encode and decode values and errors.

This is intended for testing. Method calls intercepted in this manner are not sent to platform plugins.

The provided handler must return a Future that completes with the return value of the call. The value will be encoded using MethodCodec.encodeSuccessEnvelope, to act as if platform plugin had returned that value.

Implementation

void setMockMethodCallHandler(Future<dynamic> handler(MethodCall call)) {
  BinaryMessages.setMockMessageHandler(
    name,
    handler == null ? null : (ByteData message) => _handleAsMethodCall(message, handler),
  );
}