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

Commit 27d3835

Browse files
committed
Add null safety to web implementation
1 parent b877b70 commit 27d3835

File tree

4 files changed

+23
-41
lines changed

4 files changed

+23
-41
lines changed

packages/url_launcher/url_launcher_web/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.2.0-nullsafety
2+
3+
- Migrate to null safety.
4+
15
# 0.1.4+2
26

37
- Move `lib/third_party` to `lib/src/third_party`.

packages/url_launcher/url_launcher_web/lib/url_launcher_web.dart

+10-10
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const _safariTargetTopSchemes = {
1616
'tel',
1717
'sms',
1818
};
19-
String _getUrlScheme(String url) => Uri.tryParse(url)?.scheme;
19+
String? _getUrlScheme(String url) => Uri.tryParse(url)?.scheme;
2020

2121
bool _isSafariTargetTopScheme(String url) =>
2222
_safariTargetTopSchemes.contains(_getUrlScheme(url));
@@ -35,7 +35,7 @@ class UrlLauncherPlugin extends UrlLauncherPlatform {
3535
}.union(_safariTargetTopSchemes);
3636

3737
/// A constructor that allows tests to override the window object used by the plugin.
38-
UrlLauncherPlugin({@visibleForTesting html.Window debugWindow})
38+
UrlLauncherPlugin({@visibleForTesting html.Window? debugWindow})
3939
: _window = debugWindow ?? html.window {
4040
_isSafari = navigatorIsSafari(_window.navigator);
4141
}
@@ -49,7 +49,7 @@ class UrlLauncherPlugin extends UrlLauncherPlatform {
4949
///
5050
/// Returns the newly created window.
5151
@visibleForTesting
52-
html.WindowBase openNewWindow(String url, {String webOnlyWindowName}) {
52+
html.WindowBase openNewWindow(String url, {String? webOnlyWindowName}) {
5353
// We need to open mailto, tel and sms urls on the _top window context on safari browsers.
5454
// See https://github.com/flutter/flutter/issues/51461 for reference.
5555
final target = webOnlyWindowName ??
@@ -65,13 +65,13 @@ class UrlLauncherPlugin extends UrlLauncherPlatform {
6565
@override
6666
Future<bool> launch(
6767
String url, {
68-
@required bool useSafariVC,
69-
@required bool useWebView,
70-
@required bool enableJavaScript,
71-
@required bool enableDomStorage,
72-
@required bool universalLinksOnly,
73-
@required Map<String, String> headers,
74-
String webOnlyWindowName,
68+
bool useSafariVC = false,
69+
bool useWebView = false,
70+
bool enableJavaScript = false,
71+
bool enableDomStorage = false,
72+
bool universalLinksOnly = false,
73+
Map<String, String> headers = const <String, String>{},
74+
String? webOnlyWindowName,
7575
}) {
7676
return Future<bool>.value(
7777
openNewWindow(url, webOnlyWindowName: webOnlyWindowName) != null);

packages/url_launcher/url_launcher_web/pubspec.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher/u
44
# 0.1.y+z is compatible with 1.0.0, if you land a breaking change bump
55
# the version to 2.0.0.
66
# See more details: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0
7-
version: 0.1.4+2
7+
version: 0.2.0-nullsafety
88

99
flutter:
1010
plugin:
@@ -21,19 +21,19 @@ dependencies:
2121
sdk: flutter
2222
flutter_web_plugins:
2323
sdk: flutter
24-
meta: ^1.1.7
24+
meta: ^1.3.0-nullsafety.3
2525

2626
dev_dependencies:
2727
flutter_test:
2828
sdk: flutter
2929
# TODO(mvanbeusekom): Update to use pub.dev once null safety version is published.
3030
url_launcher:
3131
path: ../url_launcher
32-
pedantic: ^1.8.0
32+
pedantic: ^1.10.0-nullsafety.1
3333
mockito: ^4.1.1
3434
integration_test:
3535
path: ../../integration_test
3636

3737
environment:
38-
sdk: ">=2.2.0 <3.0.0"
38+
sdk: ">=2.10.0-56.0.dev <3.0.0"
3939
flutter: ">=1.10.0 <2.0.0"

packages/url_launcher/url_launcher_web/test/test_driver/url_launcher_web_integration.dart

+5-27
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import 'dart:html' as html;
66
import 'package:flutter_test/flutter_test.dart';
77
import 'package:url_launcher_web/url_launcher_web.dart';
8+
// TODO(mvanbeusekom): Remove once Mockito is migrated to null safety.
9+
// @dart = 2.9
810
import 'package:mockito/mockito.dart';
911
import 'package:integration_test/integration_test.dart';
1012

@@ -16,10 +18,10 @@ void main() {
1618
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
1719

1820
group('UrlLauncherPlugin', () {
19-
_MockWindow mockWindow;
20-
_MockNavigator mockNavigator;
21+
late _MockWindow mockWindow;
22+
late _MockNavigator mockNavigator;
2123

22-
UrlLauncherPlugin plugin;
24+
late UrlLauncherPlugin plugin;
2325

2426
setUp(() {
2527
mockWindow = _MockWindow();
@@ -70,12 +72,6 @@ void main() {
7072
expect(
7173
plugin.launch(
7274
'https://www.google.com',
73-
useSafariVC: null,
74-
useWebView: null,
75-
universalLinksOnly: null,
76-
enableDomStorage: null,
77-
enableJavaScript: null,
78-
headers: null,
7975
),
8076
completion(isTrue));
8177
});
@@ -84,12 +80,6 @@ void main() {
8480
expect(
8581
plugin.launch(
8682
87-
useSafariVC: null,
88-
useWebView: null,
89-
universalLinksOnly: null,
90-
enableDomStorage: null,
91-
enableJavaScript: null,
92-
headers: null,
9383
),
9484
completion(isTrue));
9585
});
@@ -98,12 +88,6 @@ void main() {
9888
expect(
9989
plugin.launch(
10090
'tel:5551234567',
101-
useSafariVC: null,
102-
useWebView: null,
103-
universalLinksOnly: null,
104-
enableDomStorage: null,
105-
enableJavaScript: null,
106-
headers: null,
10791
),
10892
completion(isTrue));
10993
});
@@ -112,12 +96,6 @@ void main() {
11296
expect(
11397
plugin.launch(
11498
'sms:+19725551212?body=hello%20there',
115-
useSafariVC: null,
116-
useWebView: null,
117-
universalLinksOnly: null,
118-
enableDomStorage: null,
119-
enableJavaScript: null,
120-
headers: null,
12199
),
122100
completion(isTrue));
123101
});

0 commit comments

Comments
 (0)