Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
[plugin_platform_interface] Don't use const Object as a token (#2417)
Browse files Browse the repository at this point in the history
  • Loading branch information
amirh authored Dec 13, 2019
1 parent 862ef6c commit 189fa93
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 4 additions & 0 deletions packages/plugin_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin_platform_interface/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand All @@ -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 {}
2 changes: 1 addition & 1 deletion packages/plugin_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 189fa93

Please sign in to comment.