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

Commit 6c57e87

Browse files
[url_launcher] Update platforms to NNBD stable (#3584)
Updates all versions to stable. Converts all desktop examples to null-safety, and migrates Linux and macOS to use platform interface for examples rather than app-facing package to eliminate circular dependencies (implementation copied directly from Windows).
1 parent 1baec7a commit 6c57e87

File tree

21 files changed

+86
-306
lines changed

21 files changed

+86
-306
lines changed

packages/url_launcher/url_launcher_linux/CHANGELOG.md

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
1-
## 2.0.0-nullsafety
2-
3-
* Update version for consistency with other implementations.
4-
5-
## 0.1.0-nullsafety.3
1+
## 2.0.0
62

3+
* Migrate to null safety.
74
* Update the example app: remove the deprecated `RaisedButton` and `FlatButton` widgets.
8-
9-
## 0.1.0-nullsafety.2
10-
115
* Fix outdated links across a number of markdown files ([#3276](https://github.com/flutter/plugins/pull/3276))
12-
13-
## 0.1.0-nullsafety.1
14-
15-
* Migrate to null safety.
6+
* Set `implementation` in pubspec.yaml
167

178
## 0.0.2+1
189

packages/url_launcher/url_launcher_linux/example/integration_test/url_launcher_test.dart

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

5+
// @dart = 2.9
6+
57
import 'package:flutter_test/flutter_test.dart';
68
import 'package:integration_test/integration_test.dart';
7-
import 'package:url_launcher/url_launcher.dart';
9+
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';
810

911
void main() {
1012
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
1113

1214
testWidgets('canLaunch', (WidgetTester _) async {
13-
expect(await canLaunch('randomstring'), false);
14-
15-
// Generally all devices should have some default browser.
16-
expect(await canLaunch('http://flutter.dev'), true);
15+
UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
1716

18-
// Desktop will not necessarily support sms:.
17+
expect(await launcher.canLaunch('randomstring'), false);
1918

20-
// tel: and mailto: links may not be openable on every device. iOS
21-
// simulators notably can't open these link types.
19+
// Generally all devices should have some default browser.
20+
expect(await launcher.canLaunch('http://flutter.dev'), true);
2221
});
2322
}

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

Lines changed: 11 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import 'dart:async';
88
import 'package:flutter/material.dart';
9-
import 'package:url_launcher/url_launcher.dart';
9+
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';
1010

1111
void main() {
1212
runApp(MyApp());
@@ -26,85 +26,32 @@ class MyApp extends StatelessWidget {
2626
}
2727

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

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

3636
class _MyHomePageState extends State<MyHomePage> {
37-
Future<void> _launched;
38-
String _phone = '';
37+
Future<void>? _launched;
3938

4039
Future<void> _launchInBrowser(String url) async {
41-
if (await canLaunch(url)) {
42-
await launch(
40+
if (await UrlLauncherPlatform.instance.canLaunch(url)) {
41+
await UrlLauncherPlatform.instance.launch(
4342
url,
44-
forceSafariVC: false,
45-
forceWebView: false,
46-
headers: <String, String>{'my_header_key': 'my_header_value'},
43+
useSafariVC: false,
44+
useWebView: false,
45+
enableJavaScript: false,
46+
enableDomStorage: false,
47+
universalLinksOnly: false,
48+
headers: <String, String>{},
4749
);
4850
} else {
4951
throw 'Could not launch $url';
5052
}
5153
}
5254

53-
Future<void> _launchInWebViewOrVC(String url) async {
54-
if (await canLaunch(url)) {
55-
await launch(
56-
url,
57-
forceSafariVC: true,
58-
forceWebView: true,
59-
headers: <String, String>{'my_header_key': 'my_header_value'},
60-
);
61-
} else {
62-
throw 'Could not launch $url';
63-
}
64-
}
65-
66-
Future<void> _launchInWebViewWithJavaScript(String url) async {
67-
if (await canLaunch(url)) {
68-
await launch(
69-
url,
70-
forceSafariVC: true,
71-
forceWebView: true,
72-
enableJavaScript: true,
73-
);
74-
} else {
75-
throw 'Could not launch $url';
76-
}
77-
}
78-
79-
Future<void> _launchInWebViewWithDomStorage(String url) async {
80-
if (await canLaunch(url)) {
81-
await launch(
82-
url,
83-
forceSafariVC: true,
84-
forceWebView: true,
85-
enableDomStorage: true,
86-
);
87-
} else {
88-
throw 'Could not launch $url';
89-
}
90-
}
91-
92-
Future<void> _launchUniversalLinkIos(String url) async {
93-
if (await canLaunch(url)) {
94-
final bool nativeAppLaunchSucceeded = await launch(
95-
url,
96-
forceSafariVC: false,
97-
universalLinksOnly: true,
98-
);
99-
if (!nativeAppLaunchSucceeded) {
100-
await launch(
101-
url,
102-
forceSafariVC: true,
103-
);
104-
}
105-
}
106-
}
107-
10855
Widget _launchStatus(BuildContext context, AsyncSnapshot<void> snapshot) {
10956
if (snapshot.hasError) {
11057
return Text('Error: ${snapshot.error}');
@@ -113,14 +60,6 @@ class _MyHomePageState extends State<MyHomePage> {
11360
}
11461
}
11562

116-
Future<void> _makePhoneCall(String url) async {
117-
if (await canLaunch(url)) {
118-
await launch(url);
119-
} else {
120-
throw 'Could not launch $url';
121-
}
122-
}
123-
12463
@override
12564
Widget build(BuildContext context) {
12665
const String toLaunch = 'https://www.cylog.org/headers/';
@@ -133,19 +72,6 @@ class _MyHomePageState extends State<MyHomePage> {
13372
Column(
13473
mainAxisAlignment: MainAxisAlignment.center,
13574
children: <Widget>[
136-
Padding(
137-
padding: const EdgeInsets.all(16.0),
138-
child: TextField(
139-
onChanged: (String text) => _phone = text,
140-
decoration: const InputDecoration(
141-
hintText: 'Input the phone number to launch')),
142-
),
143-
ElevatedButton(
144-
onPressed: () => setState(() {
145-
_launched = _makePhoneCall('tel:$_phone');
146-
}),
147-
child: const Text('Make phone call'),
148-
),
14975
const Padding(
15076
padding: EdgeInsets.all(16.0),
15177
child: Text(toLaunch),
@@ -157,33 +83,6 @@ class _MyHomePageState extends State<MyHomePage> {
15783
child: const Text('Launch in browser'),
15884
),
15985
const Padding(padding: EdgeInsets.all(16.0)),
160-
ElevatedButton(
161-
onPressed: () => setState(() {
162-
_launched = _launchInWebViewOrVC(toLaunch);
163-
}),
164-
child: const Text('Launch in app'),
165-
),
166-
ElevatedButton(
167-
onPressed: () => setState(() {
168-
_launched = _launchInWebViewWithJavaScript(toLaunch);
169-
}),
170-
child: const Text('Launch in app(JavaScript ON)'),
171-
),
172-
ElevatedButton(
173-
onPressed: () => setState(() {
174-
_launched = _launchInWebViewWithDomStorage(toLaunch);
175-
}),
176-
child: const Text('Launch in app(DOM storage ON)'),
177-
),
178-
const Padding(padding: EdgeInsets.all(16.0)),
179-
ElevatedButton(
180-
onPressed: () => setState(() {
181-
_launched = _launchUniversalLinkIos(toLaunch);
182-
}),
183-
child: const Text(
184-
'Launch a universal link in a native app, fallback to Safari.(Youtube)'),
185-
),
186-
const Padding(padding: EdgeInsets.all(16.0)),
18786
FutureBuilder<void>(future: _launched, builder: _launchStatus),
18887
],
18988
),

packages/url_launcher/url_launcher_linux/example/pubspec.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@ description: Demonstrates how to use the url_launcher plugin.
44
dependencies:
55
flutter:
66
sdk: flutter
7-
url_launcher: any
87
url_launcher_linux:
98
# When depending on this package from a real application you should use:
109
# url_launcher_linux: ^x.y.z
1110
# See https://dart.dev/tools/pub/dependencies#version-constraints
1211
# The example app is bundled with the plugin so we use a path dependency on
1312
# the parent directory to use the current plugin's version.
1413
path: ../
14+
url_launcher_platform_interface: ^2.0.0
1515

1616
dev_dependencies:
1717
integration_test:
1818
path: ../../../integration_test
1919
flutter_driver:
2020
sdk: flutter
21-
pedantic: ^1.8.0
21+
pedantic: ^1.10.0
2222

2323
flutter:
2424
uses-material-design: true
2525

2626
environment:
27-
sdk: ">=2.1.0 <3.0.0"
28-
flutter: ">=1.12.8"
27+
sdk: ">=2.12.0-259.9.beta <3.0.0"
28+
flutter: ">=1.20.0"

packages/url_launcher/url_launcher_linux/example/test_driver/integration_test.dart

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

5+
// @dart = 2.9
6+
57
import 'dart:async';
68
import 'dart:convert';
79
import 'dart:io';

packages/url_launcher/url_launcher_linux/pubspec.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
name: url_launcher_linux
22
description: Linux implementation of the url_launcher plugin.
3-
version: 2.0.0-nullsafety
3+
version: 2.0.0
44
homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher_linux
55

66
flutter:
77
plugin:
8+
implements: url_launcher
89
platforms:
910
linux:
1011
pluginClass: UrlLauncherPlugin
1112

1213
environment:
13-
sdk: ">=2.12.0-0 <3.0.0"
14-
flutter: ">=1.12.8"
14+
sdk: ">=2.12.0-259.9.beta <3.0.0"
15+
flutter: ">=1.20.0"
1516

1617
dependencies:
1718
flutter:

packages/url_launcher/url_launcher_macos/CHANGELOG.md

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
1-
## 2.0.0-nullsafety
2-
3-
* Update version to (semi-belatedly) meet 1.0-consistency promise.
4-
5-
# 0.1.0-nullsafety.2
6-
7-
* Update the example app: remove the deprecated `RaisedButton` and `FlatButton` widgets.
8-
9-
# 0.1.0-nullsafety.1
10-
11-
* Bump SDK to support null safety.
12-
13-
# 0.1.0-nullsafety
1+
## 2.0.0
142

153
* Migrate to null safety.
4+
* Update the example app: remove the deprecated `RaisedButton` and `FlatButton` widgets.
5+
* Set `implementation` in pubspec.yaml
166

177
## 0.0.2+1
188

packages/url_launcher/url_launcher_macos/example/integration_test/url_launcher_test.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
// @dart = 2.9
6+
57
import 'package:flutter_test/flutter_test.dart';
68
import 'package:integration_test/integration_test.dart';
7-
import 'package:url_launcher/url_launcher.dart';
9+
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';
810

911
void main() {
1012
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
1113

1214
testWidgets('canLaunch', (WidgetTester _) async {
13-
expect(await canLaunch('randomstring'), false);
15+
UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
16+
17+
expect(await launcher.canLaunch('randomstring'), false);
1418

1519
// Generally all devices should have some default browser.
16-
expect(await canLaunch('http://flutter.dev'), true);
20+
expect(await launcher.canLaunch('http://flutter.dev'), true);
1721

1822
// Generally all devices should have some default SMS app.
19-
expect(await canLaunch('sms:5555555555'), true);
20-
21-
// tel: and mailto: links may not be openable on every device. iOS
22-
// simulators notably can't open these link types.
23+
expect(await launcher.canLaunch('sms:5555555555'), true);
2324
});
2425
}

0 commit comments

Comments
 (0)