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

[url_launcher] Prepare plugin repo for binding API improvements. #4136

Merged
merged 1 commit into from
Jul 4, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions packages/url_launcher/url_launcher/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 6.0.9

* Silenced warnings that may occur during build when using a very
recent version of Flutter relating to null safety.

## 6.0.8

* Adding API level 30 required package visibility configuration to the example's AndroidManifest.xml and README
Expand Down
26 changes: 19 additions & 7 deletions packages/url_launcher/url_launcher/lib/url_launcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@ Future<bool> launch(
bool previousAutomaticSystemUiAdjustment = true;
if (statusBarBrightness != null &&
defaultTargetPlatform == TargetPlatform.iOS &&
WidgetsBinding.instance != null) {
previousAutomaticSystemUiAdjustment =
WidgetsBinding.instance!.renderView.automaticSystemUiAdjustment;
WidgetsBinding.instance!.renderView.automaticSystemUiAdjustment = false;
_ambiguate(WidgetsBinding.instance) != null) {
previousAutomaticSystemUiAdjustment = _ambiguate(WidgetsBinding.instance)!
.renderView
.automaticSystemUiAdjustment;
_ambiguate(WidgetsBinding.instance)!
.renderView
.automaticSystemUiAdjustment = false;
SystemChrome.setSystemUIOverlayStyle(statusBarBrightness == Brightness.light
? SystemUiOverlayStyle.dark
: SystemUiOverlayStyle.light);
Expand All @@ -104,9 +107,11 @@ Future<bool> launch(
webOnlyWindowName: webOnlyWindowName,
);

if (statusBarBrightness != null && WidgetsBinding.instance != null) {
WidgetsBinding.instance!.renderView.automaticSystemUiAdjustment =
previousAutomaticSystemUiAdjustment;
if (statusBarBrightness != null &&
_ambiguate(WidgetsBinding.instance) != null) {
_ambiguate(WidgetsBinding.instance)!
.renderView
.automaticSystemUiAdjustment = previousAutomaticSystemUiAdjustment;
}

return result;
Expand Down Expand Up @@ -139,3 +144,10 @@ Future<bool> canLaunch(String urlString) async {
Future<void> closeWebView() async {
return await UrlLauncherPlatform.instance.closeWebView();
}

/// This allows a value of type T or T? to be treated as a value of type T?.
///
/// We use this so that APIs that have become non-nullable can still be used
/// with `!` and `?` on the stable branch.
// TODO(ianh): Remove this once we roll stable in late 2021.
T? _ambiguate<T>(T? value) => value;
2 changes: 1 addition & 1 deletion packages/url_launcher/url_launcher/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for launching a URL. Supports
web, phone, SMS, and email schemes.
repository: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+url_launcher%22
version: 6.0.8
version: 6.0.9

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down
12 changes: 10 additions & 2 deletions packages/url_launcher/url_launcher/test/url_launcher_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ void main() {
..setResponse(true);

final TestWidgetsFlutterBinding binding =
TestWidgetsFlutterBinding.ensureInitialized()
_anonymize(TestWidgetsFlutterBinding.ensureInitialized())
as TestWidgetsFlutterBinding;
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
binding.renderView.automaticSystemUiAdjustment = true;
Expand Down Expand Up @@ -268,7 +268,7 @@ void main() {
..setResponse(true);

final TestWidgetsFlutterBinding binding =
TestWidgetsFlutterBinding.ensureInitialized()
_anonymize(TestWidgetsFlutterBinding.ensureInitialized())
as TestWidgetsFlutterBinding;
debugDefaultTargetPlatformOverride = TargetPlatform.android;
expect(binding.renderView.automaticSystemUiAdjustment, true);
Expand All @@ -283,3 +283,11 @@ void main() {
});
});
}

/// This removes the type information from a value so that it can be cast
/// to another type even if that cast is redundant.
///
/// We use this so that APIs whose type have become more descriptive can still
/// be used on the stable branch where they require a cast.
// TODO(ianh): Remove this once we roll stable in late 2021.
Object? _anonymize<T>(T? value) => value;
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.0.4

* Silenced warnings that may occur during build when using a very
recent version of Flutter relating to null safety.

## 2.0.3

* Migrate `pushRouteNameToFramework` to use ChannelBuffers API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ typedef _SendMessage = Function(String, ByteData?, void Function(ByteData?));
Future<ByteData> pushRouteNameToFramework(Object? _, String routeName) {
final Completer<ByteData> completer = Completer<ByteData>();
SystemNavigator.routeInformationUpdated(location: routeName);
final _SendMessage sendMessage =
WidgetsBinding.instance?.platformDispatcher.onPlatformMessage ??
ui.channelBuffers.push;
final _SendMessage sendMessage = _ambiguate(WidgetsBinding.instance)
?.platformDispatcher
.onPlatformMessage ??
ui.channelBuffers.push;
sendMessage(
'flutter/navigation',
_codec.encodeMethodCall(
Expand All @@ -102,3 +103,10 @@ Future<ByteData> pushRouteNameToFramework(Object? _, String routeName) {
);
return completer.future;
}

/// This allows a value of type T or T? to be treated as a value of type T?.
///
/// We use this so that APIs that have become non-nullable can still be used
/// with `!` and `?` on the stable branch.
// TODO(ianh): Remove this once we roll stable in late 2021.
T? _ambiguate<T>(T? value) => value;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/tree/master/packages/url_launcher
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+url_launcher%22
# 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: 2.0.3
version: 2.0.4

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down