From a317c2144c0f2dd7719a690c729946c8b805e67b Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Fri, 13 Dec 2019 10:15:53 -0800 Subject: [PATCH 1/5] [plugin_platform_interface] Don't use const Object as a token --- packages/plugin_platform_interface/CHANGELOG.md | 4 ++++ packages/plugin_platform_interface/README.md | 2 +- .../lib/plugin_platform_interface.dart | 2 +- packages/plugin_platform_interface/pubspec.yaml | 2 +- .../test/plugin_platform_interface_test.dart | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/plugin_platform_interface/CHANGELOG.md b/packages/plugin_platform_interface/CHANGELOG.md index 29f2ef9c1b7f..8476877b33b4 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 interface apeear as mock on 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..608c64b318f3 100644 --- a/packages/plugin_platform_interface/lib/plugin_platform_interface.dart +++ b/packages/plugin_platform_interface/lib/plugin_platform_interface.dart @@ -91,7 +91,7 @@ abstract class PlatformInterface { /// ``` @visibleForTesting abstract class MockPlatformInterfaceMixin implements PlatformInterface { - static const Object _token = Object(); + static final Object _token = Object(); @override Object get _instanceToken => _token; 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); From 04049442acf3d85069d92ae669e2296441f274f8 Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Fri, 13 Dec 2019 10:58:22 -0800 Subject: [PATCH 2/5] Check for MockPlatformInterface by type --- .../lib/plugin_platform_interface.dart | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/plugin_platform_interface/lib/plugin_platform_interface.dart b/packages/plugin_platform_interface/lib/plugin_platform_interface.dart index 608c64b318f3..9d6302864f88 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,10 +67,10 @@ abstract class PlatformInterface { throw AssertionError( '`MockPlatformInterfaceMixin` is not intended for use in release builds.'); } + return; } if (!identical(token, instance._instanceToken)) { - throw AssertionError( - 'Platform interfaces must not be implemented with `implements`'); + throw AssertionError('Platform interfaces must not be implemented with `implements`'); } } } @@ -91,8 +91,6 @@ abstract class PlatformInterface { /// ``` @visibleForTesting abstract class MockPlatformInterfaceMixin implements PlatformInterface { - static final Object _token = Object(); - @override - Object get _instanceToken => _token; + Object get _instanceToken => null; } From 9d16e7bd9c7d293ad497a1fa91452370b8b403ac Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Fri, 13 Dec 2019 11:03:03 -0800 Subject: [PATCH 3/5] remove unneeded override --- .../lib/plugin_platform_interface.dart | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/plugin_platform_interface/lib/plugin_platform_interface.dart b/packages/plugin_platform_interface/lib/plugin_platform_interface.dart index 9d6302864f88..7d861d43149c 100644 --- a/packages/plugin_platform_interface/lib/plugin_platform_interface.dart +++ b/packages/plugin_platform_interface/lib/plugin_platform_interface.dart @@ -90,7 +90,4 @@ abstract class PlatformInterface { /// implements UrlLauncherPlatform {} /// ``` @visibleForTesting -abstract class MockPlatformInterfaceMixin implements PlatformInterface { - @override - Object get _instanceToken => null; -} +abstract class MockPlatformInterfaceMixin implements PlatformInterface {} From dc921ee94cd5d970e9ecd505d543089b3ed0682b Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Fri, 13 Dec 2019 11:06:40 -0800 Subject: [PATCH 4/5] Update packages/plugin_platform_interface/CHANGELOG.md Co-Authored-By: Collin Jackson --- packages/plugin_platform_interface/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin_platform_interface/CHANGELOG.md b/packages/plugin_platform_interface/CHANGELOG.md index 8476877b33b4..9fa28ec7873c 100644 --- a/packages/plugin_platform_interface/CHANGELOG.md +++ b/packages/plugin_platform_interface/CHANGELOG.md @@ -1,6 +1,6 @@ ## 1.0.1 -* Fixed a bug that made all platform interface apeear as mock on release builds (https://github.com/flutter/flutter/issues/46941). +* 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. From 3807281570fdfa1a6cbc575434682f73ce87036c Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Fri, 13 Dec 2019 11:12:36 -0800 Subject: [PATCH 5/5] format --- .../lib/plugin_platform_interface.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/plugin_platform_interface/lib/plugin_platform_interface.dart b/packages/plugin_platform_interface/lib/plugin_platform_interface.dart index 7d861d43149c..be4871928686 100644 --- a/packages/plugin_platform_interface/lib/plugin_platform_interface.dart +++ b/packages/plugin_platform_interface/lib/plugin_platform_interface.dart @@ -70,7 +70,8 @@ abstract class PlatformInterface { return; } if (!identical(token, instance._instanceToken)) { - throw AssertionError('Platform interfaces must not be implemented with `implements`'); + throw AssertionError( + 'Platform interfaces must not be implemented with `implements`'); } } }