Unverified Commit 30f8d3b3 authored by Matt Carroll's avatar Matt Carroll Committed by GitHub

Fix window bug in _sendPlatformMessage() (#27541). (#27564)

parent dfa489c3
......@@ -37,7 +37,13 @@ class BinaryMessages {
static Future<ByteData> _sendPlatformMessage(String channel, ByteData message) {
final Completer<ByteData> completer = Completer<ByteData>();
ServicesBinding.instance.window.sendPlatformMessage(channel, message, (ByteData reply) {
// ui.window is accessed directly instead of using ServicesBinding.instance.window
// because this method might be invoked before any binding is initialized.
// This issue was reported in #27541. It is not ideal to statically access
// ui.window because the Window may be dependency injected elsewhere with
// a different instance. However, static access at this location seems to be
// the least bad option.
ui.window.sendPlatformMessage(channel, message, (ByteData reply) {
try {
completer.complete(reply);
} catch (exception, stack) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment