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

Commit ab36fed

Browse files
authored
[url_launcher] Url launcher platform interface null safety (#3142)
1 parent 6018398 commit ab36fed

File tree

7 files changed

+60
-23
lines changed

7 files changed

+60
-23
lines changed

packages/url_launcher/url_launcher_platform_interface/CHANGELOG.md

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

37
* Added webOnlyWindowName parameter
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_platform_interface/lib/method_channel_url_launcher.dart

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import 'dart:async';
66

77
import 'package:flutter/services.dart';
8-
import 'package:meta/meta.dart' show required;
98

109
import 'url_launcher_platform_interface.dart';
1110

@@ -18,7 +17,7 @@ class MethodChannelUrlLauncher extends UrlLauncherPlatform {
1817
return _channel.invokeMethod<bool>(
1918
'canLaunch',
2019
<String, Object>{'url': url},
21-
);
20+
).then((value) => value ?? false);
2221
}
2322

2423
@override
@@ -29,13 +28,13 @@ class MethodChannelUrlLauncher extends UrlLauncherPlatform {
2928
@override
3029
Future<bool> launch(
3130
String url, {
32-
@required bool useSafariVC,
33-
@required bool useWebView,
34-
@required bool enableJavaScript,
35-
@required bool enableDomStorage,
36-
@required bool universalLinksOnly,
37-
@required Map<String, String> headers,
38-
String webOnlyWindowName,
31+
required bool useSafariVC,
32+
required bool useWebView,
33+
required bool enableJavaScript,
34+
required bool enableDomStorage,
35+
required bool universalLinksOnly,
36+
required Map<String, String> headers,
37+
String? webOnlyWindowName,
3938
}) {
4039
return _channel.invokeMethod<bool>(
4140
'launch',
@@ -48,6 +47,6 @@ class MethodChannelUrlLauncher extends UrlLauncherPlatform {
4847
'universalLinksOnly': universalLinksOnly,
4948
'headers': headers,
5049
},
51-
);
50+
).then((value) => value ?? false);
5251
}
5352
}

packages/url_launcher/url_launcher_platform_interface/lib/url_launcher_platform_interface.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import 'dart:async';
66

7-
import 'package:meta/meta.dart' show required;
87
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
98

109
import 'method_channel_url_launcher.dart';
@@ -49,13 +48,13 @@ abstract class UrlLauncherPlatform extends PlatformInterface {
4948
/// in `package:url_launcher/url_launcher.dart`.
5049
Future<bool> launch(
5150
String url, {
52-
@required bool useSafariVC,
53-
@required bool useWebView,
54-
@required bool enableJavaScript,
55-
@required bool enableDomStorage,
56-
@required bool universalLinksOnly,
57-
@required Map<String, String> headers,
58-
String webOnlyWindowName,
51+
required bool useSafariVC,
52+
required bool useWebView,
53+
required bool enableJavaScript,
54+
required bool enableDomStorage,
55+
required bool universalLinksOnly,
56+
required Map<String, String> headers,
57+
String? webOnlyWindowName,
5958
}) {
6059
throw UnimplementedError('launch() has not been implemented.');
6160
}

packages/url_launcher/url_launcher_platform_interface/pubspec.yaml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@ description: A common platform interface for the url_launcher plugin.
33
homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher_platform_interface
44
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
55
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
6-
version: 1.0.8
6+
version: 2.0.0-nullsafety
77

88
dependencies:
99
flutter:
1010
sdk: flutter
11-
meta: ^1.0.5
12-
plugin_platform_interface: ^1.0.1
11+
# TODO (mvanbeusekom): use pub.dev once 1.10.0-nullsafety released.
12+
plugin_platform_interface:
13+
git:
14+
url: https://github.com/flutter/plugins.git
15+
ref: nnbd
16+
path: packages/plugin_platform_interface
1317

1418
dev_dependencies:
1519
flutter_test:
1620
sdk: flutter
1721
mockito: ^4.1.1
18-
pedantic: ^1.8.0
22+
pedantic: ^1.10.0-nullsafety.1
1923

2024
environment:
21-
sdk: ">=2.1.0 <3.0.0"
25+
sdk: '>=2.10.0-56.0.dev <3.0.0'
2226
flutter: ">=1.9.1+hotfix.4 <2.0.0"

packages/url_launcher/url_launcher_platform_interface/test/method_channel_url_launcher_test.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
// TODO(mvanbeusekom): Remove once Mockito is migrated to null safety.
6+
// @dart = 2.9
57
import 'package:mockito/mockito.dart';
68
import 'package:flutter/services.dart';
79
import 'package:flutter_test/flutter_test.dart';
@@ -41,6 +43,10 @@ void main() {
4143
final List<MethodCall> log = <MethodCall>[];
4244
channel.setMockMethodCallHandler((MethodCall methodCall) async {
4345
log.add(methodCall);
46+
47+
// Return null explicitly instead of relying on the implicit null
48+
// returned by the method channel if no return statement is specified.
49+
return null;
4450
});
4551

4652
final MethodChannelUrlLauncher launcher = MethodChannelUrlLauncher();
@@ -61,6 +67,12 @@ void main() {
6167
);
6268
});
6369

70+
test('canLaunch should return false if platform returns null', () async {
71+
final canLaunch = await launcher.canLaunch('http://example.com/');
72+
73+
expect(canLaunch, false);
74+
});
75+
6476
test('launch', () async {
6577
await launcher.launch(
6678
'http://example.com/',
@@ -269,6 +281,20 @@ void main() {
269281
);
270282
});
271283

284+
test('launch should return false if platform returns null', () async {
285+
final launched = await launcher.launch(
286+
'http://example.com/',
287+
useSafariVC: true,
288+
useWebView: false,
289+
enableJavaScript: false,
290+
enableDomStorage: false,
291+
universalLinksOnly: false,
292+
headers: const <String, String>{},
293+
);
294+
295+
expect(launched, false);
296+
});
297+
272298
test('closeWebView default behavior', () async {
273299
await launcher.closeWebView();
274300
expect(

script/incremental_build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ CUSTOM_ANALYSIS_PLUGINS=(
2525
"plugin_platform_interface"
2626
"video_player/video_player_web"
2727
"google_maps_flutter/google_maps_flutter_web"
28+
"url_launcher/url_launcher_platform_interface"
2829
)
2930
# Comma-separated string of the list above
3031
readonly CUSTOM_FLAG=$(IFS=, ; echo "${CUSTOM_ANALYSIS_PLUGINS[*]}")

0 commit comments

Comments
 (0)