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

This commit is contained in:
Matt Carroll 2019-02-05 14:44:20 -08:00 committed by GitHub
parent dfa489c394
commit 30f8d3b392
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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) {