Skip to content

Commit 189fa93

Browse files
authored
[plugin_platform_interface] Don't use const Object as a token (flutter#2417)
1 parent 862ef6c commit 189fa93

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

packages/plugin_platform_interface/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.1
2+
3+
* Fixed a bug that made all platform interfaces appear as mocks in release builds (https://github.com/flutter/flutter/issues/46941).
4+
15
## 1.0.0 - Initial release.
26

37
* Provides `PlatformInterface` with common mechanism for enforcing that a platform interface

packages/plugin_platform_interface/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ abstract class UrlLauncherPlatform extends PlatformInterface {
1818
1919
static UrlLauncherPlatform _instance = MethodChannelUrlLauncher();
2020
21-
static const Object _token = Object();
21+
static final Object _token = Object();
2222
2323
static UrlLauncherPlatform get instance => _instance;
2424

packages/plugin_platform_interface/lib/plugin_platform_interface.dart

+3-7
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ abstract class PlatformInterface {
5757
/// This is implemented as a static method so that it cannot be overridden
5858
/// with `noSuchMethod`.
5959
static void verifyToken(PlatformInterface instance, Object token) {
60-
if (identical(instance._instanceToken, MockPlatformInterfaceMixin._token)) {
60+
if (instance is MockPlatformInterfaceMixin) {
6161
bool assertionsEnabled = false;
6262
assert(() {
6363
assertionsEnabled = true;
@@ -67,6 +67,7 @@ abstract class PlatformInterface {
6767
throw AssertionError(
6868
'`MockPlatformInterfaceMixin` is not intended for use in release builds.');
6969
}
70+
return;
7071
}
7172
if (!identical(token, instance._instanceToken)) {
7273
throw AssertionError(
@@ -90,9 +91,4 @@ abstract class PlatformInterface {
9091
/// implements UrlLauncherPlatform {}
9192
/// ```
9293
@visibleForTesting
93-
abstract class MockPlatformInterfaceMixin implements PlatformInterface {
94-
static const Object _token = Object();
95-
96-
@override
97-
Object get _instanceToken => _token;
98-
}
94+
abstract class MockPlatformInterfaceMixin implements PlatformInterface {}

packages/plugin_platform_interface/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ description: Reusable base class for Flutter plugin platform interfaces.
1212
# be done when absolutely necessary and after the ecosystem has already migrated to 1.X.Y version
1313
# that is forward compatible with 2.0.0 (ideally the ecosystem have migrated to depend on:
1414
# `plugin_platform_interface: >=1.X.Y <3.0.0`).
15-
version: 1.0.0
15+
version: 1.0.1
1616

1717
homepage: https://github.com/flutter/plugins/plugin_platform_interface
1818

packages/plugin_platform_interface/test/plugin_platform_interface_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'package:plugin_platform_interface/plugin_platform_interface.dart';
1010
class SamplePluginPlatform extends PlatformInterface {
1111
SamplePluginPlatform() : super(token: _token);
1212

13-
static const Object _token = Object();
13+
static final Object _token = Object();
1414

1515
static set instance(SamplePluginPlatform instance) {
1616
PlatformInterface.verifyToken(instance, _token);

0 commit comments

Comments
 (0)