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

[url_launcher] Migrates the url_launcher_web package to null safety #3171

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
605cf17
Migrate to null safety
mvanbeusekom Oct 12, 2020
b69ebe4
canLaunch and launch should return false if value is null
mvanbeusekom Oct 13, 2020
41b5db1
Processed feedback on PR 3142
mvanbeusekom Oct 14, 2020
30f0939
Migrate to null safety
mvanbeusekom Oct 13, 2020
08af97a
Rebased with nnbd branch
mvanbeusekom Oct 14, 2020
b199e62
Add null safety to web implementation
mvanbeusekom Oct 14, 2020
eb05fd3
Update Dart SDK version
mvanbeusekom Oct 15, 2020
138a960
Depend on plugin_platform_interface from GIT
mvanbeusekom Oct 15, 2020
951ea0a
Bump major version
mvanbeusekom Oct 16, 2020
87b3a26
Add new line at end of file
mvanbeusekom Oct 16, 2020
a048074
Revert "Add null safety to web implementation"
mvanbeusekom Oct 20, 2020
08895ec
Disable dependency on web until nnbd is supported
mvanbeusekom Oct 20, 2020
83d2035
Depend on GIT
mvanbeusekom Oct 20, 2020
c017d79
Add null safety to web implementation
mvanbeusekom Oct 20, 2020
befd618
Migrate to null safety
mvanbeusekom Oct 12, 2020
98e00fd
canLaunch and launch should return false if value is null
mvanbeusekom Oct 13, 2020
7f5d97c
Processed feedback on PR 3142
mvanbeusekom Oct 14, 2020
716d4e6
Migrate to null safety
mvanbeusekom Oct 13, 2020
8547126
Rebased with nnbd branch
mvanbeusekom Oct 14, 2020
8a2c80c
Add null safety to web implementation
mvanbeusekom Oct 14, 2020
fd9bae3
Update Dart SDK version
mvanbeusekom Oct 15, 2020
4fb1cee
Depend on plugin_platform_interface from GIT
mvanbeusekom Oct 15, 2020
e1a0b6c
Bump major version
mvanbeusekom Oct 16, 2020
9d4445d
Add new line at end of file
mvanbeusekom Oct 16, 2020
0ac5be0
Revert "Add null safety to web implementation"
mvanbeusekom Oct 20, 2020
6bab67b
Disable dependency on web until nnbd is supported
mvanbeusekom Oct 20, 2020
42719e7
Depend on GIT
mvanbeusekom Oct 20, 2020
0e022ed
Update to latest nnbd branch
mvanbeusekom Oct 20, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/url_launcher/url_launcher/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 6.0.0-nullsafety

* Migrate to null safety.

## 5.7.4

* Update android compileSdkVersion to 29.
Expand Down
4 changes: 4 additions & 0 deletions packages/url_launcher/url_launcher/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include: ../../../analysis_options.yaml
analyzer:
enable-experiment:
- non-nullable
4 changes: 2 additions & 2 deletions packages/url_launcher/url_launcher/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ 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;
late Future<void> _launched;
String _phone = '';

Future<void> _launchInBrowser(String url) async {
Expand Down
9 changes: 7 additions & 2 deletions packages/url_launcher/url_launcher/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ dev_dependencies:
path: ../../../integration_test
flutter_driver:
sdk: flutter
pedantic: ^1.8.0
pedantic: ^1.10.0-nullsafety.1
mockito: ^4.1.1
plugin_platform_interface: ^1.0.0
# TODO (mvanbeusekom): Update to use pub.dev once 1.10.0-nullsafety released.
plugin_platform_interface:
git:
url: https://github.com/flutter/plugins.git
ref: nnbd
path: packages/plugin_platform_interface

flutter:
uses-material-design: true
47 changes: 23 additions & 24 deletions packages/url_launcher/url_launcher/lib/url_launcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,15 @@ import 'package:url_launcher_platform_interface/url_launcher_platform_interface.
/// is set to true and the universal link failed to launch.
Future<bool> launch(
String urlString, {
bool forceSafariVC,
bool forceWebView,
bool enableJavaScript,
bool enableDomStorage,
bool universalLinksOnly,
Map<String, String> headers,
Brightness statusBarBrightness,
String webOnlyWindowName,
bool forceSafariVC = true,
bool forceWebView = false,
bool enableJavaScript = false,
bool enableDomStorage = false,
bool universalLinksOnly = false,
Map<String, String> headers = const <String, String>{},
Brightness? statusBarBrightness,
String? webOnlyWindowName,
}) async {
assert(urlString != null);
final Uri url = Uri.parse(urlString.trimLeft());
final bool isWebURL = url.scheme == 'http' || url.scheme == 'https';
if ((forceSafariVC == true || forceWebView == true) && !isWebURL) {
Expand All @@ -81,29 +80,32 @@ Future<bool> launch(
/// [true] so that ui is automatically computed if [statusBarBrightness] is set.
bool previousAutomaticSystemUiAdjustment = true;
if (statusBarBrightness != null &&
defaultTargetPlatform == TargetPlatform.iOS) {
defaultTargetPlatform == TargetPlatform.iOS &&
WidgetsBinding.instance != null) {
previousAutomaticSystemUiAdjustment =
WidgetsBinding.instance.renderView.automaticSystemUiAdjustment;
WidgetsBinding.instance.renderView.automaticSystemUiAdjustment = false;
WidgetsBinding.instance!.renderView.automaticSystemUiAdjustment;
WidgetsBinding.instance!.renderView.automaticSystemUiAdjustment = false;
SystemChrome.setSystemUIOverlayStyle(statusBarBrightness == Brightness.light
? SystemUiOverlayStyle.dark
: SystemUiOverlayStyle.light);
}

final bool result = await UrlLauncherPlatform.instance.launch(
urlString,
useSafariVC: forceSafariVC ?? isWebURL,
useWebView: forceWebView ?? false,
enableJavaScript: enableJavaScript ?? false,
enableDomStorage: enableDomStorage ?? false,
universalLinksOnly: universalLinksOnly ?? false,
headers: headers ?? <String, String>{},
useSafariVC: forceSafariVC,
useWebView: forceWebView,
enableJavaScript: enableJavaScript,
enableDomStorage: enableDomStorage,
universalLinksOnly: universalLinksOnly,
headers: headers,
webOnlyWindowName: webOnlyWindowName,
);
assert(previousAutomaticSystemUiAdjustment != null);
if (statusBarBrightness != null) {
WidgetsBinding.instance.renderView.automaticSystemUiAdjustment =

if (statusBarBrightness != null && WidgetsBinding.instance != null) {
WidgetsBinding.instance!.renderView.automaticSystemUiAdjustment =
previousAutomaticSystemUiAdjustment;
}

return result;
}

Expand All @@ -115,9 +117,6 @@ Future<bool> launch(
/// For more information see the [Managing package visibility](https://developer.android.com/training/basics/intents/package-visibility)
/// article in the Android docs.
Future<bool> canLaunch(String urlString) async {
if (urlString == null) {
return false;
}
return await UrlLauncherPlatform.instance.canLaunch(urlString);
}

Expand Down
28 changes: 19 additions & 9 deletions packages/url_launcher/url_launcher/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: url_launcher
description: Flutter plugin for launching a URL on Android and iOS. Supports
web, phone, SMS, and email schemes.
homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher
version: 5.7.4
version: 6.0.0-nullsafety

flutter:
plugin:
Expand All @@ -12,8 +12,9 @@ flutter:
pluginClass: UrlLauncherPlugin
ios:
pluginClass: FLTURLLauncherPlugin
web:
default_package: url_launcher_web
# TODO(mvanbeusekom): Temporary disabled until web is migrated to nnbd (advised by @blasten).
#web:
# default_package: url_launcher_web
linux:
default_package: url_laucher_linux
macos:
Expand All @@ -24,25 +25,34 @@ flutter:
dependencies:
flutter:
sdk: flutter
url_launcher_platform_interface: ^1.0.8
# TODO(mvanbeusekom): Update to use pub.dev once null safety version is published.
url_launcher_platform_interface:
path: ../url_launcher_platform_interface
# The design on https://flutter.dev/go/federated-plugins was to leave
# this constraint as "any". We cannot do it right now as it fails pub publish
# validation, so we set a ^ constraint.
# TODO(amirh): Revisit this (either update this part in the design or the pub tool).
# https://github.com/flutter/flutter/issues/46264
url_launcher_web: ^0.1.3
url_launcher_linux: ^0.0.1
url_launcher_macos: ^0.0.1
url_launcher_windows: ^0.0.1
# TODO (mvanbeusekom): Update to use pub.dev once 0.2.0-nullsafety released.
url_launcher_web:
path: ../url_launcher_web

dev_dependencies:
flutter_test:
sdk: flutter
test: ^1.3.0
test: ^1.10.0-nullsafety.1
mockito: ^4.1.1
plugin_platform_interface: ^1.0.0
pedantic: ^1.8.0
# TODO (mvanbeusekom): Update to use pub.dev once 1.10.0-nullsafety released.
plugin_platform_interface:
git:
url: https://github.com/flutter/plugins.git
ref: nnbd
path: packages/plugin_platform_interface
pedantic: ^1.10.0-nullsafety.1

environment:
sdk: ">=2.1.0 <3.0.0"
sdk: ">=2.10.0-56.0.dev <3.0.0"
flutter: ">=1.12.13+hotfix.5 <2.0.0"
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

import 'dart:async';
import 'dart:ui';

import 'package:flutter_test/flutter_test.dart';
// TODO(mvanbeusekom): Remove once Mockito is migrated to null safety.
// @dart = 2.9
import 'package:mockito/mockito.dart';
import 'package:flutter/foundation.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
Expand Down Expand Up @@ -41,10 +44,6 @@ void main() {
});
});
group('launch', () {
test('requires a non-null urlString', () {
expect(() => launch(null), throwsAssertionError);
});

test('default behavior', () async {
await launch('http://flutter.dev/');
expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version: 2.0.0-nullsafety
dependencies:
flutter:
sdk: flutter
# TODO (mvanbeusekom): use pub.dev once 1.10.0-nullsafety released.
# TODO (mvanbeusekom): Update to use pub.dev once 1.10.0-nullsafety released.
plugin_platform_interface:
git:
url: https://github.com/flutter/plugins.git
Expand Down
4 changes: 4 additions & 0 deletions packages/url_launcher/url_launcher_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.2.0-nullsafety

- Migrate to null safety.

# 0.1.4+2

- Move `lib/third_party` to `lib/src/third_party`.
Expand Down
4 changes: 4 additions & 0 deletions packages/url_launcher/url_launcher_web/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include: ../../../analysis_options.yaml
analyzer:
enable-experiment:
- non-nullable
20 changes: 10 additions & 10 deletions packages/url_launcher/url_launcher_web/lib/url_launcher_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const _safariTargetTopSchemes = {
'tel',
'sms',
};
String _getUrlScheme(String url) => Uri.tryParse(url)?.scheme;
String? _getUrlScheme(String url) => Uri.tryParse(url)?.scheme;

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

/// A constructor that allows tests to override the window object used by the plugin.
UrlLauncherPlugin({@visibleForTesting html.Window debugWindow})
UrlLauncherPlugin({@visibleForTesting html.Window? debugWindow})
: _window = debugWindow ?? html.window {
_isSafari = navigatorIsSafari(_window.navigator);
}
Expand All @@ -49,7 +49,7 @@ class UrlLauncherPlugin extends UrlLauncherPlatform {
///
/// Returns the newly created window.
@visibleForTesting
html.WindowBase openNewWindow(String url, {String webOnlyWindowName}) {
html.WindowBase openNewWindow(String url, {String? webOnlyWindowName}) {
// We need to open mailto, tel and sms urls on the _top window context on safari browsers.
// See https://github.com/flutter/flutter/issues/51461 for reference.
final target = webOnlyWindowName ??
Expand All @@ -65,13 +65,13 @@ class UrlLauncherPlugin extends UrlLauncherPlatform {
@override
Future<bool> launch(
String url, {
@required bool useSafariVC,
@required bool useWebView,
@required bool enableJavaScript,
@required bool enableDomStorage,
@required bool universalLinksOnly,
@required Map<String, String> headers,
String webOnlyWindowName,
bool useSafariVC = false,
bool useWebView = false,
bool enableJavaScript = false,
bool enableDomStorage = false,
bool universalLinksOnly = false,
Map<String, String> headers = const <String, String>{},
String? webOnlyWindowName,
}) {
return Future<bool>.value(
openNewWindow(url, webOnlyWindowName: webOnlyWindowName) != null);
Expand Down
16 changes: 10 additions & 6 deletions packages/url_launcher/url_launcher_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher/u
# 0.1.y+z is compatible with 1.0.0, if you land a breaking change bump
# the version to 2.0.0.
# See more details: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0
version: 0.1.4+2
version: 0.2.0-nullsafety

flutter:
plugin:
Expand All @@ -14,22 +14,26 @@ flutter:
fileName: url_launcher_web.dart

dependencies:
url_launcher_platform_interface: ^1.0.8
# TODO(mvanbeusekom): Update to use pub.dev once null safety version is published.
url_launcher_platform_interface:
path: ../url_launcher_platform_interface
flutter:
sdk: flutter
flutter_web_plugins:
sdk: flutter
meta: ^1.1.7
meta: ^1.3.0-nullsafety.3

dev_dependencies:
flutter_test:
sdk: flutter
url_launcher: ^5.2.5
pedantic: ^1.8.0
# TODO(mvanbeusekom): Update to use pub.dev once null safety version is published.
url_launcher:
path: ../url_launcher
pedantic: ^1.10.0-nullsafety.1
mockito: ^4.1.1
integration_test:
path: ../../integration_test

environment:
sdk: ">=2.2.0 <3.0.0"
sdk: ">=2.10.0-56.0.dev <3.0.0"
flutter: ">=1.10.0 <2.0.0"
2 changes: 1 addition & 1 deletion packages/url_launcher/url_launcher_web/test/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: regular_integration_tests
publish_to: none

environment:
sdk: ">=2.2.2 <3.0.0"
sdk: ">=2.10.0-56.0.dev <3.0.0"

dependencies:
flutter:
Expand Down
Loading