From 86b4e5a452b67bc93c11560112934b0c3676c4a5 Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Fri, 13 Dec 2019 12:20:43 -0800 Subject: [PATCH] [plugin_platform_interface] Don't use const Object as a token (#2417) --- packages/plugin_platform_interface/CHANGELOG.md | 4 ++++ packages/plugin_platform_interface/README.md | 2 +- .../lib/plugin_platform_interface.dart | 10 +++------- packages/plugin_platform_interface/pubspec.yaml | 2 +- .../test/plugin_platform_interface_test.dart | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/plugin_platform_interface/CHANGELOG.md b/packages/plugin_platform_interface/CHANGELOG.md index 29f2ef9c1b7f..9fa28ec7873c 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 f213bc777d76..9fdbd8a75fe2 100644 --- a/packages/plugin_platform_interface/README.md +++ b/packages/plugin_platform_interface/README.md @@ -18,7 +18,7 @@ abstract class UrlLauncherPlatform extends PlatformInterface { 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 6f78768c1ebe..be4871928686 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 @@ abstract class PlatformInterface { /// 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 @@ abstract class PlatformInterface { throw AssertionError( '`MockPlatformInterfaceMixin` is not intended for use in release builds.'); } + return; } if (!identical(token, instance._instanceToken)) { throw AssertionError( @@ -90,9 +91,4 @@ abstract class PlatformInterface { /// 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 29d08e14ba9a..4adfe6ad2f72 100644 --- a/packages/plugin_platform_interface/pubspec.yaml +++ b/packages/plugin_platform_interface/pubspec.yaml @@ -12,7 +12,7 @@ description: Reusable base class for Flutter plugin platform interfaces. # 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 b8fc4ffae5dc..0488c20f3efb 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 @@ import 'package:plugin_platform_interface/plugin_platform_interface.dart'; 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);