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

Commit f77d6db

Browse files
committed
Migrate to null safety
1 parent 68a2dea commit f77d6db

File tree

6 files changed

+56
-41
lines changed

6 files changed

+56
-41
lines changed

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: 15 additions & 7 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.2
5+
version: 5.8.0-nullsafety
66

77
flutter:
88
plugin:
@@ -24,25 +24,33 @@ flutter:
2424
dependencies:
2525
flutter:
2626
sdk: flutter
27-
url_launcher_platform_interface: ^1.0.8
27+
# TODO(mvanbeusekom): Update to use pub.dev once null safety version is published.
28+
url_launcher_platform_interface:
29+
path: ../url_launcher_platform_interface
2830
# The design on https://flutter.dev/go/federated-plugins was to leave
2931
# this constraint as "any". We cannot do it right now as it fails pub publish
3032
# validation, so we set a ^ constraint.
3133
# TODO(amirh): Revisit this (either update this part in the design or the pub tool).
3234
# https://github.com/flutter/flutter/issues/46264
33-
url_launcher_web: ^0.1.3
35+
url_launcher_web:
36+
path: ../url_launcher_web
3437
url_launcher_linux: ^0.0.1
3538
url_launcher_macos: ^0.0.1
3639
url_launcher_windows: ^0.0.1
3740

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

4654
environment:
47-
sdk: ">=2.1.0 <3.0.0"
55+
sdk: ">=2.10.0-56.0.dev <3.0.0"
4856
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_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:

0 commit comments

Comments
 (0)