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

[url_launcher] Initialize previousAutomaticSystemUiAdjustment in launch #2757

Merged
merged 5 commits into from
May 13, 2020
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
4 changes: 4 additions & 0 deletions packages/url_launcher/url_launcher/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 5.4.8

* Initialize `previousAutomaticSystemUiAdjustment` in launch method.

## 5.4.7

* Update lower bound of dart dependency to 2.1.0.
Expand Down
5 changes: 4 additions & 1 deletion packages/url_launcher/url_launcher/lib/url_launcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ Future<bool> launch(
message: 'To use webview or safariVC, you need to pass'
'in a web URL. This $urlString is not a web URL.');
}
bool previousAutomaticSystemUiAdjustment;

/// [true] so that ui is automatically computed if [statusBarBrightness] is set.
bool previousAutomaticSystemUiAdjustment = true;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you know why true instead of false? Could you add a comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added a comment. I think it should be true because if it's false when the statusBarBrightness is set, then there will be a delay in computing the system UI.

if (statusBarBrightness != null &&
defaultTargetPlatform == TargetPlatform.iOS) {
previousAutomaticSystemUiAdjustment =
Expand All @@ -92,6 +94,7 @@ Future<bool> launch(
universalLinksOnly: universalLinksOnly ?? false,
headers: headers ?? <String, String>{},
);
assert(previousAutomaticSystemUiAdjustment != null);
if (statusBarBrightness != null) {
WidgetsBinding.instance.renderView.automaticSystemUiAdjustment =
previousAutomaticSystemUiAdjustment;
Expand Down
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 @@ -2,7 +2,7 @@ name: url_launcher
description: Flutter plugin for launching a URL on Android and iOS. Supports
web, phone, SMS, and email schemes.
homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher
version: 5.4.7
version: 5.4.8

flutter:
plugin:
Expand Down
15 changes: 15 additions & 0 deletions packages/url_launcher/url_launcher/test/url_launcher_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,21 @@ void main() {
await launchResult;
expect(binding.renderView.automaticSystemUiAdjustment, isTrue);
});

test('sets automaticSystemUiAdjustment to not be null', () async {
final TestWidgetsFlutterBinding binding =
TestWidgetsFlutterBinding.ensureInitialized();
debugDefaultTargetPlatformOverride = TargetPlatform.android;
expect(binding.renderView.automaticSystemUiAdjustment, true);
final Future<bool> launchResult =
launch('http://flutter.dev/', statusBarBrightness: Brightness.dark);

// The automaticSystemUiAdjustment should be set before the launch
// and equal to true after the launch result is complete.
expect(binding.renderView.automaticSystemUiAdjustment, true);
await launchResult;
expect(binding.renderView.automaticSystemUiAdjustment, true);
});
});
}

Expand Down