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

Commit dc957b3

Browse files
committed
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.
1 parent 2745bad commit dc957b3

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

packages/url_launcher/url_launcher/lib/url_launcher.dart

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,13 @@ Future<bool> launch(
8484
bool previousAutomaticSystemUiAdjustment = true;
8585
if (statusBarBrightness != null &&
8686
defaultTargetPlatform == TargetPlatform.iOS &&
87-
WidgetsBinding.instance != null) {
88-
previousAutomaticSystemUiAdjustment =
89-
WidgetsBinding.instance!.renderView.automaticSystemUiAdjustment;
90-
WidgetsBinding.instance!.renderView.automaticSystemUiAdjustment = false;
87+
_ambiguate(WidgetsBinding.instance) != null) {
88+
previousAutomaticSystemUiAdjustment = _ambiguate(WidgetsBinding.instance)!
89+
.renderView
90+
.automaticSystemUiAdjustment;
91+
_ambiguate(WidgetsBinding.instance)!
92+
.renderView
93+
.automaticSystemUiAdjustment = false;
9194
SystemChrome.setSystemUIOverlayStyle(statusBarBrightness == Brightness.light
9295
? SystemUiOverlayStyle.dark
9396
: SystemUiOverlayStyle.light);
@@ -104,9 +107,11 @@ Future<bool> launch(
104107
webOnlyWindowName: webOnlyWindowName,
105108
);
106109

107-
if (statusBarBrightness != null && WidgetsBinding.instance != null) {
108-
WidgetsBinding.instance!.renderView.automaticSystemUiAdjustment =
109-
previousAutomaticSystemUiAdjustment;
110+
if (statusBarBrightness != null &&
111+
_ambiguate(WidgetsBinding.instance) != null) {
112+
_ambiguate(WidgetsBinding.instance)!
113+
.renderView
114+
.automaticSystemUiAdjustment = previousAutomaticSystemUiAdjustment;
110115
}
111116

112117
return result;
@@ -139,3 +144,10 @@ Future<bool> canLaunch(String urlString) async {
139144
Future<void> closeWebView() async {
140145
return await UrlLauncherPlatform.instance.closeWebView();
141146
}
147+
148+
/// This allows a value of type T or T? to be treated as a value of type T?.
149+
///
150+
/// We use this so that APIs that have become non-nullable can still be used
151+
/// with `!` and `?` on the stable branch.
152+
// TODO(ianh): Remove this once we roll stable in late 2021.
153+
T? _ambiguate<T>(T? value) => value;

packages/url_launcher/url_launcher/test/url_launcher_test.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ void main() {
239239
..setResponse(true);
240240

241241
final TestWidgetsFlutterBinding binding =
242-
TestWidgetsFlutterBinding.ensureInitialized()
242+
_anonymize(TestWidgetsFlutterBinding.ensureInitialized())
243243
as TestWidgetsFlutterBinding;
244244
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
245245
binding.renderView.automaticSystemUiAdjustment = true;
@@ -268,7 +268,7 @@ void main() {
268268
..setResponse(true);
269269

270270
final TestWidgetsFlutterBinding binding =
271-
TestWidgetsFlutterBinding.ensureInitialized()
271+
_anonymize(TestWidgetsFlutterBinding.ensureInitialized())
272272
as TestWidgetsFlutterBinding;
273273
debugDefaultTargetPlatformOverride = TargetPlatform.android;
274274
expect(binding.renderView.automaticSystemUiAdjustment, true);
@@ -283,3 +283,11 @@ void main() {
283283
});
284284
});
285285
}
286+
287+
/// This removes the type information from a value so that it can be cast
288+
/// to another type even if that cast is redundant.
289+
///
290+
/// We use this so that APIs whose type have become more descriptive can still
291+
/// be used on the stable branch where they require a cast.
292+
// TODO(ianh): Remove this once we roll stable in late 2021.
293+
Object? _anonymize<T>(T? value) => value;

packages/url_launcher/url_launcher_platform_interface/lib/link.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ typedef _SendMessage = Function(String, ByteData?, void Function(ByteData?));
8787
Future<ByteData> pushRouteNameToFramework(Object? _, String routeName) {
8888
final Completer<ByteData> completer = Completer<ByteData>();
8989
SystemNavigator.routeInformationUpdated(location: routeName);
90-
final _SendMessage sendMessage =
91-
WidgetsBinding.instance?.platformDispatcher.onPlatformMessage ??
92-
ui.channelBuffers.push;
90+
final _SendMessage sendMessage = _ambiguate(WidgetsBinding.instance)
91+
?.platformDispatcher
92+
.onPlatformMessage ??
93+
ui.channelBuffers.push;
9394
sendMessage(
9495
'flutter/navigation',
9596
_codec.encodeMethodCall(
@@ -102,3 +103,10 @@ Future<ByteData> pushRouteNameToFramework(Object? _, String routeName) {
102103
);
103104
return completer.future;
104105
}
106+
107+
/// This allows a value of type T or T? to be treated as a value of type T?.
108+
///
109+
/// We use this so that APIs that have become non-nullable can still be used
110+
/// with `!` and `?` on the stable branch.
111+
// TODO(ianh): Remove this once we roll stable in late 2021.
112+
T? _ambiguate<T>(T? value) => value;

0 commit comments

Comments
 (0)