Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.0.4

* Use an assertion to ensure `isMock` is not used in release builds.
* Prevent `noSuchMethod` from being used to bypass `isMock`.

## 1.0.3

* Minor DartDoc changes and add a lint for missing DartDocs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ abstract class UrlLauncherPlatform {
/// Mockito mocks are implementing this class with `implements` which is forbidden for anything
/// other than mocks (see class docs). This property provides a backdoor for mockito mocks to
/// skip the verification that the class isn't implemented with `implements`.
///
/// This flag has no effect in release builds.
@visibleForTesting
bool get isMock => false;

Expand All @@ -36,9 +38,17 @@ abstract class UrlLauncherPlatform {
// TODO(amirh): Extract common platform interface logic.
// https://github.com/flutter/flutter/issues/43368
static set instance(UrlLauncherPlatform instance) {
if (!instance.isMock) {
bool assertionsEnabled = false;
assert(() {
assertionsEnabled = true;
return true;
}());
if (!assertionsEnabled || !instance.isMock) {
try {
instance._verifyProvidesDefaultImplementations();
if (_verificationToken != instance._verifyProvidesDefaultImplementations()) {
throw AssertionError(
'Platform interfaces must not be implemented with `implements`');
}
} on NoSuchMethodError catch (_) {
throw AssertionError(
'Platform interfaces must not be implemented with `implements`');
Expand Down Expand Up @@ -79,5 +89,9 @@ abstract class UrlLauncherPlatform {
//
// This private method is called by the instance setter, which fails if the class is
// implemented with `implements`.
void _verifyProvidesDefaultImplementations() {}
Object _verifyProvidesDefaultImplementations() => _verificationToken;

// Private object used to determine if `_verifyProvidesDefaultImplementations`
// has been overridden with `noSuchMethod`.
static Object _verificationToken = Object();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ author: Flutter Team <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher_platform_interface
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 1.0.3
version: 1.0.4

dependencies:
flutter:
Expand Down