Skip to content

Commit 9786682

Browse files
authored
[web] Add BackgroundIsolateBinaryMessenger.ensureInitialized to web. (#145786)
This PR makes the static API of the `BackgroundIsolateBinaryMessenger` consistent between its web and IO implementations. This way, multi-platform applications will compile for the web when using the `ensureInitialized` method (even though it'll throw at runtime, like the `instance` getter, because isolates are not supported on the web). ### Issues * Fixes: flutter/flutter#145260
1 parent d2a1938 commit 9786682

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

dev/bots/test.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,12 @@ Future<void> _runBuildTests() async {
598598
path.join('dev', 'integration_tests', 'web_compile_tests'),
599599
path.join('lib', 'dart_io_import.dart'),
600600
),
601+
// Should be able to compile with a call to:
602+
// BackgroundIsolateBinaryMessenger.ensureInitialized.
603+
() => _flutterBuildDart2js(
604+
path.join('dev', 'integration_tests', 'web_compile_tests'),
605+
path.join('lib', 'background_isolate_binary_messenger.dart'),
606+
),
601607
],
602608
runForbiddenFromReleaseTests,
603609
]..shuffle(math.Random(0));
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:ui' as ui;
6+
import 'package:flutter/services.dart';
7+
8+
void main() {
9+
BackgroundIsolateBinaryMessenger.ensureInitialized(
10+
ui.RootIsolateToken.instance!
11+
);
12+
}

packages/flutter/lib/src/services/_background_isolate_binary_messenger_web.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'dart:ui' as ui show RootIsolateToken;
56
import 'binding.dart';
67

78
/// Stand-in for non-web platforms' [BackgroundIsolateBinaryMessenger].
@@ -10,4 +11,9 @@ class BackgroundIsolateBinaryMessenger {
1011
static BinaryMessenger get instance {
1112
throw UnsupportedError('Isolates not supported on web.');
1213
}
14+
15+
/// Throws an [UnsupportedError].
16+
static void ensureInitialized(ui.RootIsolateToken token) {
17+
throw UnsupportedError('Isolates not supported on web.');
18+
}
1319
}

0 commit comments

Comments
 (0)