Skip to content

Commit

Permalink
[url_launcher] Update platforms to NNBD stable (flutter#3584)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
stuartmorgan authored and adsonpleal committed Feb 26, 2021
1 parent f9ca21b commit 8b182e9
Show file tree
Hide file tree
Showing 21 changed files with 86 additions and 306 deletions.
15 changes: 3 additions & 12 deletions packages/url_launcher/url_launcher_linux/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
## 2.0.0-nullsafety

* Update version for consistency with other implementations.

## 0.1.0-nullsafety.3
## 2.0.0

* Migrate to null safety.
* Update the example app: remove the deprecated `RaisedButton` and `FlatButton` widgets.

## 0.1.0-nullsafety.2

* Fix outdated links across a number of markdown files ([#3276](https://github.com/flutter/plugins/pull/3276))

## 0.1.0-nullsafety.1

* Migrate to null safety.
* Set `implementation` in pubspec.yaml

## 0.0.2+1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

testWidgets('canLaunch', (WidgetTester _) async {
expect(await canLaunch('randomstring'), false);

// Generally all devices should have some default browser.
expect(await canLaunch('http://flutter.dev'), true);
UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;

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

// tel: and mailto: links may not be openable on every device. iOS
// simulators notably can't open these link types.
// Generally all devices should have some default browser.
expect(await launcher.canLaunch('http://flutter.dev'), true);
});
}
123 changes: 11 additions & 112 deletions packages/url_launcher/url_launcher_linux/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';

void main() {
runApp(MyApp());
Expand All @@ -26,85 +26,32 @@ class MyApp extends StatelessWidget {
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;

@override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
Future<void> _launched;
String _phone = '';
Future<void>? _launched;

Future<void> _launchInBrowser(String url) async {
if (await canLaunch(url)) {
await launch(
if (await UrlLauncherPlatform.instance.canLaunch(url)) {
await UrlLauncherPlatform.instance.launch(
url,
forceSafariVC: false,
forceWebView: false,
headers: <String, String>{'my_header_key': 'my_header_value'},
useSafariVC: false,
useWebView: false,
enableJavaScript: false,
enableDomStorage: false,
universalLinksOnly: false,
headers: <String, String>{},
);
} else {
throw 'Could not launch $url';
}
}

Future<void> _launchInWebViewOrVC(String url) async {
if (await canLaunch(url)) {
await launch(
url,
forceSafariVC: true,
forceWebView: true,
headers: <String, String>{'my_header_key': 'my_header_value'},
);
} else {
throw 'Could not launch $url';
}
}

Future<void> _launchInWebViewWithJavaScript(String url) async {
if (await canLaunch(url)) {
await launch(
url,
forceSafariVC: true,
forceWebView: true,
enableJavaScript: true,
);
} else {
throw 'Could not launch $url';
}
}

Future<void> _launchInWebViewWithDomStorage(String url) async {
if (await canLaunch(url)) {
await launch(
url,
forceSafariVC: true,
forceWebView: true,
enableDomStorage: true,
);
} else {
throw 'Could not launch $url';
}
}

Future<void> _launchUniversalLinkIos(String url) async {
if (await canLaunch(url)) {
final bool nativeAppLaunchSucceeded = await launch(
url,
forceSafariVC: false,
universalLinksOnly: true,
);
if (!nativeAppLaunchSucceeded) {
await launch(
url,
forceSafariVC: true,
);
}
}
}

Widget _launchStatus(BuildContext context, AsyncSnapshot<void> snapshot) {
if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
Expand All @@ -113,14 +60,6 @@ class _MyHomePageState extends State<MyHomePage> {
}
}

Future<void> _makePhoneCall(String url) async {
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}

@override
Widget build(BuildContext context) {
const String toLaunch = 'https://www.cylog.org/headers/';
Expand All @@ -133,19 +72,6 @@ class _MyHomePageState extends State<MyHomePage> {
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: TextField(
onChanged: (String text) => _phone = text,
decoration: const InputDecoration(
hintText: 'Input the phone number to launch')),
),
ElevatedButton(
onPressed: () => setState(() {
_launched = _makePhoneCall('tel:$_phone');
}),
child: const Text('Make phone call'),
),
const Padding(
padding: EdgeInsets.all(16.0),
child: Text(toLaunch),
Expand All @@ -157,33 +83,6 @@ class _MyHomePageState extends State<MyHomePage> {
child: const Text('Launch in browser'),
),
const Padding(padding: EdgeInsets.all(16.0)),
ElevatedButton(
onPressed: () => setState(() {
_launched = _launchInWebViewOrVC(toLaunch);
}),
child: const Text('Launch in app'),
),
ElevatedButton(
onPressed: () => setState(() {
_launched = _launchInWebViewWithJavaScript(toLaunch);
}),
child: const Text('Launch in app(JavaScript ON)'),
),
ElevatedButton(
onPressed: () => setState(() {
_launched = _launchInWebViewWithDomStorage(toLaunch);
}),
child: const Text('Launch in app(DOM storage ON)'),
),
const Padding(padding: EdgeInsets.all(16.0)),
ElevatedButton(
onPressed: () => setState(() {
_launched = _launchUniversalLinkIos(toLaunch);
}),
child: const Text(
'Launch a universal link in a native app, fallback to Safari.(Youtube)'),
),
const Padding(padding: EdgeInsets.all(16.0)),
FutureBuilder<void>(future: _launched, builder: _launchStatus),
],
),
Expand Down
8 changes: 4 additions & 4 deletions packages/url_launcher/url_launcher_linux/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ description: Demonstrates how to use the url_launcher plugin.
dependencies:
flutter:
sdk: flutter
url_launcher: any
url_launcher_linux:
# When depending on this package from a real application you should use:
# url_launcher_linux: ^x.y.z
# See https://dart.dev/tools/pub/dependencies#version-constraints
# The example app is bundled with the plugin so we use a path dependency on
# the parent directory to use the current plugin's version.
path: ../
url_launcher_platform_interface: ^2.0.0

dev_dependencies:
integration_test:
path: ../../../integration_test
flutter_driver:
sdk: flutter
pedantic: ^1.8.0
pedantic: ^1.10.0

flutter:
uses-material-design: true

environment:
sdk: ">=2.1.0 <3.0.0"
flutter: ">=1.12.8"
sdk: ">=2.12.0-259.9.beta <3.0.0"
flutter: ">=1.20.0"
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

import 'dart:async';
import 'dart:convert';
import 'dart:io';
Expand Down
7 changes: 4 additions & 3 deletions packages/url_launcher/url_launcher_linux/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
name: url_launcher_linux
description: Linux implementation of the url_launcher plugin.
version: 2.0.0-nullsafety
version: 2.0.0
homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher_linux

flutter:
plugin:
implements: url_launcher
platforms:
linux:
pluginClass: UrlLauncherPlugin

environment:
sdk: ">=2.12.0-0 <3.0.0"
flutter: ">=1.12.8"
sdk: ">=2.12.0-259.9.beta <3.0.0"
flutter: ">=1.20.0"

dependencies:
flutter:
Expand Down
16 changes: 3 additions & 13 deletions packages/url_launcher/url_launcher_macos/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
## 2.0.0-nullsafety

* Update version to (semi-belatedly) meet 1.0-consistency promise.

# 0.1.0-nullsafety.2

* Update the example app: remove the deprecated `RaisedButton` and `FlatButton` widgets.

# 0.1.0-nullsafety.1

* Bump SDK to support null safety.

# 0.1.0-nullsafety
## 2.0.0

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

## 0.0.2+1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

testWidgets('canLaunch', (WidgetTester _) async {
expect(await canLaunch('randomstring'), false);
UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;

expect(await launcher.canLaunch('randomstring'), false);

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

// Generally all devices should have some default SMS app.
expect(await canLaunch('sms:5555555555'), true);

// tel: and mailto: links may not be openable on every device. iOS
// simulators notably can't open these link types.
expect(await launcher.canLaunch('sms:5555555555'), true);
});
}
Loading

0 comments on commit 8b182e9

Please sign in to comment.