setMockMethodCallHandler method
void
setMockMethodCallHandler(
- MethodChannel channel,
- Future<
Object?> ? handler(- MethodCall message
Implementation
void setMockMethodCallHandler(MethodChannel channel,
Future<Object?>? Function(MethodCall message) handler) {
if (handler == null) {
setMockMessageHandler(channel.name, null);
return;
}
setMockMessageHandler(channel.name, (ByteData? message) async {
final MethodCall call = channel.codec.decodeMethodCall(message);
try {
return channel.codec.encodeSuccessEnvelope(await handler(call));
} on PlatformException catch (error) {
return channel.codec.encodeErrorEnvelope(
code: error.code,
message: error.message,
details: error.details,
);
} on MissingPluginException {
return null;
} catch (error) {
return channel.codec.encodeErrorEnvelope(
code: 'error', message: '$error', details: null);
}
}, handler);
}