[plugin_platform_interface] Don't use const Object as a token (#2417)
diff --git a/packages/plugin_platform_interface/CHANGELOG.md b/packages/plugin_platform_interface/CHANGELOG.md
index 29f2ef9..9fa28ec 100644
--- a/packages/plugin_platform_interface/CHANGELOG.md
+++ b/packages/plugin_platform_interface/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 1.0.1
+
+* Fixed a bug that made all platform interfaces appear as mocks in release builds (https://github.com/flutter/flutter/issues/46941).
+
## 1.0.0 - Initial release.
* Provides `PlatformInterface` with common mechanism for enforcing that a platform interface
diff --git a/packages/plugin_platform_interface/README.md b/packages/plugin_platform_interface/README.md
index f213bc7..9fdbd8a 100644
--- a/packages/plugin_platform_interface/README.md
+++ b/packages/plugin_platform_interface/README.md
@@ -18,7 +18,7 @@
static UrlLauncherPlatform _instance = MethodChannelUrlLauncher();
- static const Object _token = Object();
+ static final Object _token = Object();
static UrlLauncherPlatform get instance => _instance;
diff --git a/packages/plugin_platform_interface/lib/plugin_platform_interface.dart b/packages/plugin_platform_interface/lib/plugin_platform_interface.dart
index 6f78768..be48719 100644
--- a/packages/plugin_platform_interface/lib/plugin_platform_interface.dart
+++ b/packages/plugin_platform_interface/lib/plugin_platform_interface.dart
@@ -57,7 +57,7 @@
/// This is implemented as a static method so that it cannot be overridden
/// with `noSuchMethod`.
static void verifyToken(PlatformInterface instance, Object token) {
- if (identical(instance._instanceToken, MockPlatformInterfaceMixin._token)) {
+ if (instance is MockPlatformInterfaceMixin) {
bool assertionsEnabled = false;
assert(() {
assertionsEnabled = true;
@@ -67,6 +67,7 @@
throw AssertionError(
'`MockPlatformInterfaceMixin` is not intended for use in release builds.');
}
+ return;
}
if (!identical(token, instance._instanceToken)) {
throw AssertionError(
@@ -90,9 +91,4 @@
/// implements UrlLauncherPlatform {}
/// ```
@visibleForTesting
-abstract class MockPlatformInterfaceMixin implements PlatformInterface {
- static const Object _token = Object();
-
- @override
- Object get _instanceToken => _token;
-}
+abstract class MockPlatformInterfaceMixin implements PlatformInterface {}
diff --git a/packages/plugin_platform_interface/pubspec.yaml b/packages/plugin_platform_interface/pubspec.yaml
index 29d08e1..4adfe6a 100644
--- a/packages/plugin_platform_interface/pubspec.yaml
+++ b/packages/plugin_platform_interface/pubspec.yaml
@@ -12,7 +12,7 @@
# be done when absolutely necessary and after the ecosystem has already migrated to 1.X.Y version
# that is forward compatible with 2.0.0 (ideally the ecosystem have migrated to depend on:
# `plugin_platform_interface: >=1.X.Y <3.0.0`).
-version: 1.0.0
+version: 1.0.1
homepage: https://github.com/flutter/plugins/plugin_platform_interface
diff --git a/packages/plugin_platform_interface/test/plugin_platform_interface_test.dart b/packages/plugin_platform_interface/test/plugin_platform_interface_test.dart
index b8fc4ff..0488c20 100644
--- a/packages/plugin_platform_interface/test/plugin_platform_interface_test.dart
+++ b/packages/plugin_platform_interface/test/plugin_platform_interface_test.dart
@@ -10,7 +10,7 @@
class SamplePluginPlatform extends PlatformInterface {
SamplePluginPlatform() : super(token: _token);
- static const Object _token = Object();
+ static final Object _token = Object();
static set instance(SamplePluginPlatform instance) {
PlatformInterface.verifyToken(instance, _token);