Skip to content

Commit

Permalink
[url_launcher] Switch to new analysis options (flutter#4551)
Browse files Browse the repository at this point in the history
Removes the legacy analysis options for all `url_launcher` packages, and fixes all resulting violations. Most fixes are automatic `dart fix` changes.

No version change: Most of these changes are to code that don't affect clients, or are clearly no-ops (e.g., adding a type specifier that was already strongly inferred). Only the packages where there is some potential for change—although none is actually expected—have version bumps.

Part of flutter/flutter#76229
  • Loading branch information
stuartmorgan authored Nov 30, 2021
1 parent 3990aaf commit 2ab3044
Show file tree
Hide file tree
Showing 50 changed files with 178 additions and 144 deletions.
1 change: 0 additions & 1 deletion packages/url_launcher/analysis_options.yaml

This file was deleted.

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.17

* Updates code for new analysis options.

## 6.0.16

* Moves Android and iOS implementations to federated packages.
Expand Down
10 changes: 5 additions & 5 deletions packages/url_launcher/url_launcher/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ class MyApp extends StatelessWidget {
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'URL Launcher'),
home: const MyHomePage(title: 'URL Launcher'),
);
}
}

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

@override
Expand Down Expand Up @@ -213,11 +213,11 @@ class _MyHomePageState extends State<MyHomePage> {
uri: Uri.parse(
'https://pub.dev/documentation/url_launcher/latest/link/link-library.html'),
target: LinkTarget.blank,
builder: (ctx, openLink) {
builder: (BuildContext ctx, FollowLink? openLink) {
return TextButton.icon(
onPressed: openLink,
label: Text('Link Widget documentation'),
icon: Icon(Icons.read_more),
label: const Text('Link Widget documentation'),
icon: const Icon(Icons.read_more),
);
},
),
Expand Down
5 changes: 2 additions & 3 deletions packages/url_launcher/url_launcher/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ dependencies:
path: ../

dev_dependencies:
integration_test:
sdk: flutter
flutter_driver:
sdk: flutter
pedantic: ^1.10.0
integration_test:
sdk: flutter
mockito: ^5.0.0
plugin_platform_interface: ^2.0.0

Expand Down
3 changes: 2 additions & 1 deletion packages/url_launcher/url_launcher/lib/link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

export 'src/link.dart' show Link;
export 'package:url_launcher_platform_interface/link.dart'
show FollowLink, LinkTarget, LinkWidgetBuilder;

export 'src/link.dart' show Link;
30 changes: 19 additions & 11 deletions packages/url_launcher/url_launcher/lib/src/link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,31 @@ Future<ByteData> Function(Object?, String) pushRouteToFrameworkFunction =
/// );
/// ```
class Link extends StatelessWidget implements LinkInfo {
/// Creates a widget that renders a real link on the web, and uses WebViews in
/// native platforms to open links.
const Link({
Key? key,
required this.uri,
this.target = LinkTarget.defaultTarget,
required this.builder,
}) : super(key: key);

/// Called at build time to construct the widget tree under the link.
@override
final LinkWidgetBuilder builder;

/// The destination that this link leads to.
@override
final Uri? uri;

/// The target indicating where to open the link.
@override
final LinkTarget target;

/// Whether the link is disabled or not.
@override
bool get isDisabled => uri == null;

/// Creates a widget that renders a real link on the web, and uses WebViews in
/// native platforms to open links.
Link({
Key? key,
required this.uri,
this.target = LinkTarget.defaultTarget,
required this.builder,
}) : super(key: key);

LinkDelegate get _effectiveDelegate {
return UrlLauncherPlatform.instance.linkDelegate ??
DefaultLinkDelegate.create;
Expand Down Expand Up @@ -94,8 +98,12 @@ class DefaultLinkDelegate extends StatelessWidget {
final LinkInfo link;

bool get _useWebView {
if (link.target == LinkTarget.self) return true;
if (link.target == LinkTarget.blank) return false;
if (link.target == LinkTarget.self) {
return true;
}
if (link.target == LinkTarget.blank) {
return false;
}
return false;
}

Expand Down
3 changes: 1 addition & 2 deletions packages/url_launcher/url_launcher/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for launching a URL. Supports
web, phone, SMS, and email schemes.
repository: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+url_launcher%22
version: 6.0.16
version: 6.0.17

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down Expand Up @@ -41,6 +41,5 @@ dev_dependencies:
flutter_test:
sdk: flutter
mockito: ^5.0.0
pedantic: ^1.10.0
plugin_platform_interface: ^2.0.0
test: ^1.16.3
6 changes: 3 additions & 3 deletions packages/url_launcher/url_launcher/test/link_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:url_launcher/link.dart';
import 'package:url_launcher/src/link.dart';
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';
Expand Down Expand Up @@ -118,11 +118,11 @@ void main() {
));

bool frameworkCalled = false;
Future<ByteData> Function(Object?, String) originalPushFunction =
final Future<ByteData> Function(Object?, String) originalPushFunction =
pushRouteToFrameworkFunction;
pushRouteToFrameworkFunction = (Object? _, String __) {
frameworkCalled = true;
return Future.value(ByteData(0));
return Future<ByteData>.value(ByteData(0));
};

await followLink!();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import 'dart:async';
import 'dart:ui';

import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart' show PlatformException;
import 'package:flutter_test/flutter_test.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';
import 'package:flutter/services.dart' show PlatformException;

import 'mock_url_launcher_platform.dart';

Expand Down Expand Up @@ -239,7 +239,7 @@ void main() {
..setResponse(true);

final TestWidgetsFlutterBinding binding =
_anonymize(TestWidgetsFlutterBinding.ensureInitialized())
_anonymize(TestWidgetsFlutterBinding.ensureInitialized())!
as TestWidgetsFlutterBinding;
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
binding.renderView.automaticSystemUiAdjustment = true;
Expand Down Expand Up @@ -268,7 +268,7 @@ void main() {
..setResponse(true);

final TestWidgetsFlutterBinding binding =
_anonymize(TestWidgetsFlutterBinding.ensureInitialized())
_anonymize(TestWidgetsFlutterBinding.ensureInitialized())!
as TestWidgetsFlutterBinding;
debugDefaultTargetPlatformOverride = TargetPlatform.android;
expect(binding.renderView.automaticSystemUiAdjustment, true);
Expand Down
4 changes: 4 additions & 0 deletions packages/url_launcher/url_launcher_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## NEXT

* Updates code for new analysis options.

## 6.0.13

* Splits from `shared_preferences` as a federated implementation.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

testWidgets('canLaunch', (WidgetTester _) async {
UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
final UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;

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

Expand Down
14 changes: 7 additions & 7 deletions packages/url_launcher/url_launcher_android/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ class MyApp extends StatelessWidget {
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'URL Launcher'),
home: const MyHomePage(title: 'URL Launcher'),
);
}
}

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

@override
Expand All @@ -39,7 +39,7 @@ class _MyHomePageState extends State<MyHomePage> {
String _phone = '';

Future<void> _launchInBrowser(String url) async {
UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
final UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
if (await launcher.canLaunch(url)) {
await launcher.launch(
url,
Expand All @@ -56,7 +56,7 @@ class _MyHomePageState extends State<MyHomePage> {
}

Future<void> _launchInWebViewOrVC(String url) async {
UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
final UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
if (await launcher.canLaunch(url)) {
await launcher.launch(
url,
Expand All @@ -73,7 +73,7 @@ class _MyHomePageState extends State<MyHomePage> {
}

Future<void> _launchInWebViewWithJavaScript(String url) async {
UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
final UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
if (await launcher.canLaunch(url)) {
await launcher.launch(
url,
Expand All @@ -90,7 +90,7 @@ class _MyHomePageState extends State<MyHomePage> {
}

Future<void> _launchInWebViewWithDomStorage(String url) async {
UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
final UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
if (await launcher.canLaunch(url)) {
await launcher.launch(
url,
Expand All @@ -115,7 +115,7 @@ class _MyHomePageState extends State<MyHomePage> {
}

Future<void> _makePhoneCall(String url) async {
UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
final UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
if (await launcher.canLaunch(url)) {
await launcher.launch(
url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ dependencies:
path: ../

dev_dependencies:
integration_test:
sdk: flutter
flutter_driver:
sdk: flutter
pedantic: ^1.10.0
integration_test:
sdk: flutter
mockito: ^5.0.0
plugin_platform_interface: ^2.0.0

Expand Down
1 change: 0 additions & 1 deletion packages/url_launcher/url_launcher_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ dev_dependencies:
flutter_test:
sdk: flutter
mockito: ^5.0.0
pedantic: ^1.10.0
plugin_platform_interface: ^2.0.0
test: ^1.16.3
4 changes: 4 additions & 0 deletions packages/url_launcher/url_launcher_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## NEXT

* Updates code for new analysis options.

## 6.0.13

* Splits from `url_launcher` as a federated implementation.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

testWidgets('canLaunch', (WidgetTester _) async {
UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
final UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;

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

Expand Down
16 changes: 8 additions & 8 deletions packages/url_launcher/url_launcher_ios/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ class MyApp extends StatelessWidget {
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'URL Launcher'),
home: const MyHomePage(title: 'URL Launcher'),
);
}
}

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

@override
Expand All @@ -39,7 +39,7 @@ class _MyHomePageState extends State<MyHomePage> {
String _phone = '';

Future<void> _launchInBrowser(String url) async {
UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
final UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
if (await launcher.canLaunch(url)) {
await launcher.launch(
url,
Expand All @@ -56,7 +56,7 @@ class _MyHomePageState extends State<MyHomePage> {
}

Future<void> _launchInWebViewOrVC(String url) async {
UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
final UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
if (await launcher.canLaunch(url)) {
await launcher.launch(
url,
Expand All @@ -73,7 +73,7 @@ class _MyHomePageState extends State<MyHomePage> {
}

Future<void> _launchInWebViewWithJavaScript(String url) async {
UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
final UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
if (await launcher.canLaunch(url)) {
await launcher.launch(
url,
Expand All @@ -90,7 +90,7 @@ class _MyHomePageState extends State<MyHomePage> {
}

Future<void> _launchInWebViewWithDomStorage(String url) async {
UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
final UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
if (await launcher.canLaunch(url)) {
await launcher.launch(
url,
Expand All @@ -107,7 +107,7 @@ class _MyHomePageState extends State<MyHomePage> {
}

Future<void> _launchUniversalLinkIos(String url) async {
UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
final UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
if (await launcher.canLaunch(url)) {
final bool nativeAppLaunchSucceeded = await launcher.launch(
url,
Expand Down Expand Up @@ -141,7 +141,7 @@ class _MyHomePageState extends State<MyHomePage> {
}

Future<void> _makePhoneCall(String url) async {
UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
final UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
if (await launcher.canLaunch(url)) {
await launcher.launch(
url,
Expand Down
5 changes: 2 additions & 3 deletions packages/url_launcher/url_launcher_ios/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ dependencies:
path: ../

dev_dependencies:
integration_test:
sdk: flutter
flutter_driver:
sdk: flutter
pedantic: ^1.10.0
integration_test:
sdk: flutter
mockito: ^5.0.0
plugin_platform_interface: ^2.0.0

Expand Down
1 change: 0 additions & 1 deletion packages/url_launcher/url_launcher_ios/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@ dev_dependencies:
flutter_test:
sdk: flutter
mockito: ^5.0.0
pedantic: ^1.10.0
plugin_platform_interface: ^2.0.0
test: ^1.16.3
Loading

0 comments on commit 2ab3044

Please sign in to comment.