This reverts commit c26ed03c8a.
This commit is contained in:
@@ -61,7 +61,7 @@ class Registrar extends BinaryMessenger {
|
||||
/// the [dart:ui] library. That function is only available when
|
||||
/// compiling for the web.
|
||||
void registerMessageHandler() {
|
||||
// The `ui.webOnlySetPluginHandler` function below is only defined in the Web dart:ui.
|
||||
// The function below is only defined in the Web dart:ui.
|
||||
// ignore: undefined_function
|
||||
ui.webOnlySetPluginHandler(handleFrameworkMessage);
|
||||
}
|
||||
@@ -141,7 +141,7 @@ class Registrar extends BinaryMessenger {
|
||||
@override
|
||||
Future<ByteData?> send(String channel, ByteData? message) {
|
||||
final Completer<ByteData?> completer = Completer<ByteData?>();
|
||||
ui.channelBuffers.push(channel, message, (ByteData? reply) {
|
||||
ui.window.onPlatformMessage!(channel, message, (ByteData? reply) {
|
||||
try {
|
||||
completer.complete(reply);
|
||||
} catch (exception, stack) {
|
||||
@@ -163,6 +163,26 @@ class Registrar extends BinaryMessenger {
|
||||
else
|
||||
_handlers[channel] = handler;
|
||||
}
|
||||
|
||||
@override
|
||||
bool checkMessageHandler(String channel, MessageHandler? handler) => _handlers[channel] == handler;
|
||||
|
||||
@override
|
||||
void setMockMessageHandler(
|
||||
String channel,
|
||||
MessageHandler? handler,
|
||||
) {
|
||||
throw FlutterError(
|
||||
'Setting mock handlers is not supported on the platform side.',
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool checkMockMessageHandler(String channel, MessageHandler? handler) {
|
||||
throw FlutterError(
|
||||
'Setting mock handlers is not supported on the platform side.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// This class was previously separate from [Registrar] but was merged into it
|
||||
|
||||
@@ -71,5 +71,12 @@ void main() {
|
||||
ServicesBinding.instance!.defaultBinaryMessenger
|
||||
.setMessageHandler('test_send', null);
|
||||
});
|
||||
|
||||
test('throws when trying to set a mock handler', () {
|
||||
expect(
|
||||
() => pluginBinaryMessenger.setMockMessageHandler(
|
||||
'test', (ByteData? data) async => ByteData(0)),
|
||||
throwsFlutterError);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user