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

Commit 052ec5f

Browse files
authored
[url_launcher] migrate url_launcher package to null safety (#3148)
1 parent 7dd61d9 commit 052ec5f

File tree

12 files changed

+74
-45
lines changed

12 files changed

+74
-45
lines changed

packages/url_launcher/url_launcher/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 6.0.0-nullsafety
2+
3+
* Migrate to null safety.
4+
15
## 5.7.4
26

37
* Update android compileSdkVersion to 29.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include: ../../../analysis_options.yaml
2+
analyzer:
3+
enable-experiment:
4+
- non-nullable

packages/url_launcher/url_launcher/example/lib/main.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ class MyApp extends StatelessWidget {
2727
}
2828

2929
class MyHomePage extends StatefulWidget {
30-
MyHomePage({Key key, this.title}) : super(key: key);
30+
MyHomePage({Key? key, required this.title}) : super(key: key);
3131
final String title;
3232

3333
@override
3434
_MyHomePageState createState() => _MyHomePageState();
3535
}
3636

3737
class _MyHomePageState extends State<MyHomePage> {
38-
Future<void> _launched;
38+
late Future<void> _launched;
3939
String _phone = '';
4040

4141
Future<void> _launchInBrowser(String url) async {

packages/url_launcher/url_launcher/example/pubspec.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@ dev_dependencies:
1212
path: ../../../integration_test
1313
flutter_driver:
1414
sdk: flutter
15-
pedantic: ^1.8.0
15+
pedantic: ^1.10.0-nullsafety.1
1616
mockito: ^4.1.1
17-
plugin_platform_interface: ^1.0.0
17+
# TODO (mvanbeusekom): Update to use pub.dev once 1.10.0-nullsafety released.
18+
plugin_platform_interface:
19+
git:
20+
url: https://github.com/flutter/plugins.git
21+
ref: nnbd
22+
path: packages/plugin_platform_interface
1823

1924
flutter:
2025
uses-material-design: true

packages/url_launcher/url_launcher/lib/url_launcher.dart

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,15 @@ import 'package:url_launcher_platform_interface/url_launcher_platform_interface.
5959
/// is set to true and the universal link failed to launch.
6060
Future<bool> launch(
6161
String urlString, {
62-
bool forceSafariVC,
63-
bool forceWebView,
64-
bool enableJavaScript,
65-
bool enableDomStorage,
66-
bool universalLinksOnly,
67-
Map<String, String> headers,
68-
Brightness statusBarBrightness,
69-
String webOnlyWindowName,
62+
bool forceSafariVC = true,
63+
bool forceWebView = false,
64+
bool enableJavaScript = false,
65+
bool enableDomStorage = false,
66+
bool universalLinksOnly = false,
67+
Map<String, String> headers = const <String, String>{},
68+
Brightness? statusBarBrightness,
69+
String? webOnlyWindowName,
7070
}) async {
71-
assert(urlString != null);
7271
final Uri url = Uri.parse(urlString.trimLeft());
7372
final bool isWebURL = url.scheme == 'http' || url.scheme == 'https';
7473
if ((forceSafariVC == true || forceWebView == true) && !isWebURL) {
@@ -81,29 +80,32 @@ Future<bool> launch(
8180
/// [true] so that ui is automatically computed if [statusBarBrightness] is set.
8281
bool previousAutomaticSystemUiAdjustment = true;
8382
if (statusBarBrightness != null &&
84-
defaultTargetPlatform == TargetPlatform.iOS) {
83+
defaultTargetPlatform == TargetPlatform.iOS &&
84+
WidgetsBinding.instance != null) {
8585
previousAutomaticSystemUiAdjustment =
86-
WidgetsBinding.instance.renderView.automaticSystemUiAdjustment;
87-
WidgetsBinding.instance.renderView.automaticSystemUiAdjustment = false;
86+
WidgetsBinding.instance!.renderView.automaticSystemUiAdjustment;
87+
WidgetsBinding.instance!.renderView.automaticSystemUiAdjustment = false;
8888
SystemChrome.setSystemUIOverlayStyle(statusBarBrightness == Brightness.light
8989
? SystemUiOverlayStyle.dark
9090
: SystemUiOverlayStyle.light);
9191
}
92+
9293
final bool result = await UrlLauncherPlatform.instance.launch(
9394
urlString,
94-
useSafariVC: forceSafariVC ?? isWebURL,
95-
useWebView: forceWebView ?? false,
96-
enableJavaScript: enableJavaScript ?? false,
97-
enableDomStorage: enableDomStorage ?? false,
98-
universalLinksOnly: universalLinksOnly ?? false,
99-
headers: headers ?? <String, String>{},
95+
useSafariVC: forceSafariVC,
96+
useWebView: forceWebView,
97+
enableJavaScript: enableJavaScript,
98+
enableDomStorage: enableDomStorage,
99+
universalLinksOnly: universalLinksOnly,
100+
headers: headers,
100101
webOnlyWindowName: webOnlyWindowName,
101102
);
102-
assert(previousAutomaticSystemUiAdjustment != null);
103-
if (statusBarBrightness != null) {
104-
WidgetsBinding.instance.renderView.automaticSystemUiAdjustment =
103+
104+
if (statusBarBrightness != null && WidgetsBinding.instance != null) {
105+
WidgetsBinding.instance!.renderView.automaticSystemUiAdjustment =
105106
previousAutomaticSystemUiAdjustment;
106107
}
108+
107109
return result;
108110
}
109111

@@ -115,9 +117,6 @@ Future<bool> launch(
115117
/// For more information see the [Managing package visibility](https://developer.android.com/training/basics/intents/package-visibility)
116118
/// article in the Android docs.
117119
Future<bool> canLaunch(String urlString) async {
118-
if (urlString == null) {
119-
return false;
120-
}
121120
return await UrlLauncherPlatform.instance.canLaunch(urlString);
122121
}
123122

packages/url_launcher/url_launcher/pubspec.yaml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: url_launcher
22
description: Flutter plugin for launching a URL on Android and iOS. Supports
33
web, phone, SMS, and email schemes.
44
homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher
5-
version: 5.7.4
5+
version: 6.0.0-nullsafety
66

77
flutter:
88
plugin:
@@ -12,8 +12,9 @@ flutter:
1212
pluginClass: UrlLauncherPlugin
1313
ios:
1414
pluginClass: FLTURLLauncherPlugin
15-
web:
16-
default_package: url_launcher_web
15+
# TODO(mvanbeusekom): Temporary disabled until web is migrated to nnbd (advised by @blasten).
16+
#web:
17+
# default_package: url_launcher_web
1718
linux:
1819
default_package: url_laucher_linux
1920
macos:
@@ -24,25 +25,33 @@ flutter:
2425
dependencies:
2526
flutter:
2627
sdk: flutter
27-
url_launcher_platform_interface: ^1.0.8
28+
# TODO(mvanbeusekom): Update to use pub.dev once null safety version is published.
29+
url_launcher_platform_interface:
30+
path: ../url_launcher_platform_interface
2831
# The design on https://flutter.dev/go/federated-plugins was to leave
2932
# this constraint as "any". We cannot do it right now as it fails pub publish
3033
# validation, so we set a ^ constraint.
3134
# TODO(amirh): Revisit this (either update this part in the design or the pub tool).
3235
# https://github.com/flutter/flutter/issues/46264
33-
url_launcher_web: ^0.1.3
3436
url_launcher_linux: ^0.0.1
3537
url_launcher_macos: ^0.0.1
3638
url_launcher_windows: ^0.0.1
39+
# TODO(mvanbeusekom): Temporary disabled until web is migrated to nnbd (advised by @blasten).
40+
#url_launcher_web: ^0.1.3
3741

3842
dev_dependencies:
3943
flutter_test:
4044
sdk: flutter
41-
test: ^1.3.0
45+
test: ^1.10.0-nullsafety.1
4246
mockito: ^4.1.1
43-
plugin_platform_interface: ^1.0.0
44-
pedantic: ^1.8.0
47+
# TODO (mvanbeusekom): Update to use pub.dev once 1.10.0-nullsafety released.
48+
plugin_platform_interface:
49+
git:
50+
url: https://github.com/flutter/plugins.git
51+
ref: nnbd
52+
path: packages/plugin_platform_interface
53+
pedantic: ^1.10.0-nullsafety.1
4554

4655
environment:
47-
sdk: ">=2.1.0 <3.0.0"
56+
sdk: ">=2.10.0-56.0.dev <3.0.0"
4857
flutter: ">=1.12.13+hotfix.5 <2.0.0"

packages/url_launcher/url_launcher/test/url_launcher_test.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
import 'dart:async';
88
import 'dart:ui';
9+
910
import 'package:flutter_test/flutter_test.dart';
11+
// TODO(mvanbeusekom): Remove once Mockito is migrated to null safety.
12+
// @dart = 2.9
1013
import 'package:mockito/mockito.dart';
1114
import 'package:flutter/foundation.dart';
1215
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
@@ -41,10 +44,6 @@ void main() {
4144
});
4245
});
4346
group('launch', () {
44-
test('requires a non-null urlString', () {
45-
expect(() => launch(null), throwsAssertionError);
46-
});
47-
4847
test('default behavior', () async {
4948
await launch('http://flutter.dev/');
5049
expect(

packages/url_launcher/url_launcher_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ version: 2.0.0-nullsafety
88
dependencies:
99
flutter:
1010
sdk: flutter
11-
# TODO (mvanbeusekom): use pub.dev once 1.10.0-nullsafety released.
11+
# TODO (mvanbeusekom): Update to use pub.dev once 1.10.0-nullsafety released.
1212
plugin_platform_interface:
1313
git:
1414
url: https://github.com/flutter/plugins.git
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include: ../../../analysis_options.yaml
2+
analyzer:
3+
enable-experiment:
4+
- non-nullable

packages/url_launcher/url_launcher_web/pubspec.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ flutter:
1414
fileName: url_launcher_web.dart
1515

1616
dependencies:
17-
url_launcher_platform_interface: ^1.0.8
17+
# TODO(mvanbeusekom): Update to use pub.dev once null safety version is published.
18+
url_launcher_platform_interface:
19+
path: ../url_launcher_platform_interface
1820
flutter:
1921
sdk: flutter
2022
flutter_web_plugins:
@@ -24,7 +26,9 @@ dependencies:
2426
dev_dependencies:
2527
flutter_test:
2628
sdk: flutter
27-
url_launcher: ^5.2.5
29+
# TODO(mvanbeusekom): Update to use pub.dev once null safety version is published.
30+
url_launcher:
31+
path: ../url_launcher
2832
pedantic: ^1.8.0
2933
mockito: ^4.1.1
3034
integration_test:

packages/url_launcher/url_launcher_web/test/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: regular_integration_tests
22
publish_to: none
33

44
environment:
5-
sdk: ">=2.2.2 <3.0.0"
5+
sdk: ">=2.10.0-56.0.dev <3.0.0"
66

77
dependencies:
88
flutter:

script/incremental_build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ CUSTOM_ANALYSIS_PLUGINS=(
2828
"video_player/video_player_web"
2929
"google_maps_flutter/google_maps_flutter_web"
3030
"url_launcher/url_launcher_platform_interface"
31+
"url_launcher/url_launcher"
3132
"device_info/device_info_platform_interface"
3233
"device_info/device_info"
3334
)

0 commit comments

Comments
 (0)