Thanks to visit codestin.com
Credit goes to github.com

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

[url_launcher] migrate url_launcher package to null safety #3148

Merged
merged 13 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 18 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,33 @@ 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): Temporary disabled until web is migrated to nnbd (advised by @blasten).
#url_launcher_web: ^0.1.3

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/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
8 changes: 6 additions & 2 deletions packages/url_launcher/url_launcher_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ 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:
Expand All @@ -24,7 +26,9 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
url_launcher: ^5.2.5
# TODO(mvanbeusekom): Update to use pub.dev once null safety version is published.
url_launcher:
path: ../url_launcher
pedantic: ^1.8.0
mockito: ^4.1.1
integration_test:
Expand Down
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
1 change: 1 addition & 0 deletions script/incremental_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ CUSTOM_ANALYSIS_PLUGINS=(
"video_player/video_player_web"
"google_maps_flutter/google_maps_flutter_web"
"url_launcher/url_launcher_platform_interface"
"url_launcher/url_launcher"
"device_info/device_info_platform_interface"
"device_info/device_info"
)
Expand Down