From 649f3f1d76b33e12ea394cf87e78c9d9f70da810 Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Fri, 2 Jul 2021 16:55:22 -0700 Subject: [PATCH] Prepare plugin repo for binding API improvements. Since plugins also have to work with the stable branch, we can't actually take advantage of the changes right away, so we muddle the issue in the meantime. --- .../url_launcher/url_launcher/CHANGELOG.md | 5 ++++ .../url_launcher/lib/url_launcher.dart | 26 ++++++++++++++----- .../url_launcher/url_launcher/pubspec.yaml | 2 +- .../url_launcher/test/url_launcher_test.dart | 12 +++++++-- .../CHANGELOG.md | 5 ++++ .../lib/link.dart | 14 +++++++--- .../pubspec.yaml | 2 +- 7 files changed, 52 insertions(+), 14 deletions(-) diff --git a/packages/url_launcher/url_launcher/CHANGELOG.md b/packages/url_launcher/url_launcher/CHANGELOG.md index 1e7104c453e2..1dcf7a1582a8 100644 --- a/packages/url_launcher/url_launcher/CHANGELOG.md +++ b/packages/url_launcher/url_launcher/CHANGELOG.md @@ -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 diff --git a/packages/url_launcher/url_launcher/lib/url_launcher.dart b/packages/url_launcher/url_launcher/lib/url_launcher.dart index e8d9670ec6d4..8c46520a71c4 100644 --- a/packages/url_launcher/url_launcher/lib/url_launcher.dart +++ b/packages/url_launcher/url_launcher/lib/url_launcher.dart @@ -84,10 +84,13 @@ Future 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); @@ -104,9 +107,11 @@ Future 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; @@ -139,3 +144,10 @@ Future canLaunch(String urlString) async { Future 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? value) => value; diff --git a/packages/url_launcher/url_launcher/pubspec.yaml b/packages/url_launcher/url_launcher/pubspec.yaml index 28dc71c56346..f6294ab30cc5 100644 --- a/packages/url_launcher/url_launcher/pubspec.yaml +++ b/packages/url_launcher/url_launcher/pubspec.yaml @@ -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" diff --git a/packages/url_launcher/url_launcher/test/url_launcher_test.dart b/packages/url_launcher/url_launcher/test/url_launcher_test.dart index 9b2d167483cd..04f727a57746 100644 --- a/packages/url_launcher/url_launcher/test/url_launcher_test.dart +++ b/packages/url_launcher/url_launcher/test/url_launcher_test.dart @@ -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; @@ -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); @@ -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? value) => value; diff --git a/packages/url_launcher/url_launcher_platform_interface/CHANGELOG.md b/packages/url_launcher/url_launcher_platform_interface/CHANGELOG.md index 06a2efecc500..fc56473533f2 100644 --- a/packages/url_launcher/url_launcher_platform_interface/CHANGELOG.md +++ b/packages/url_launcher/url_launcher_platform_interface/CHANGELOG.md @@ -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. diff --git a/packages/url_launcher/url_launcher_platform_interface/lib/link.dart b/packages/url_launcher/url_launcher_platform_interface/lib/link.dart index 4a414ae78f1f..ffff14feb8d7 100644 --- a/packages/url_launcher/url_launcher_platform_interface/lib/link.dart +++ b/packages/url_launcher/url_launcher_platform_interface/lib/link.dart @@ -87,9 +87,10 @@ typedef _SendMessage = Function(String, ByteData?, void Function(ByteData?)); Future pushRouteNameToFramework(Object? _, String routeName) { final Completer completer = Completer(); 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( @@ -102,3 +103,10 @@ Future 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? value) => value; diff --git a/packages/url_launcher/url_launcher_platform_interface/pubspec.yaml b/packages/url_launcher/url_launcher_platform_interface/pubspec.yaml index 9bb30c60f405..074e95b08c2c 100644 --- a/packages/url_launcher/url_launcher_platform_interface/pubspec.yaml +++ b/packages/url_launcher/url_launcher_platform_interface/pubspec.yaml @@ -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"