[url_launcher] Fix launch mode types in new APIs (#5232)

The new query APIs added in 6.2.0 accidentally used `PreferredLaunchMode`, which is only intended for the platform interface layer, rather than `LaunchMode`, which is the app-facing analog (they are separate to allow controlling when each is updated separately).

Technically this is a breaking change, but 6.2.0 was out for less than 24 hours, so extremely few people will be affected (they would have to have updated, written code against the new API, and worked around the lack of type export), and a breaking change to fix this would have much more disruptive effects on the ecosystem.

Fixes https://github.com/flutter/flutter/issues/137278
This commit is contained in:
stuartmorgan
2023-10-25 13:28:13 -07:00
committed by GitHub
parent f2124f78ab
commit fea24c5b93
5 changed files with 30 additions and 21 deletions

View File

@ -1,5 +1,12 @@
## 6.2.1
* Fixes incorrect types in `supportsLaunchMode` and
`supportsCloseForLaunchMode`.
## 6.2.0
_Retracted due to incorrect types in new APIs._
* Adds `supportsLaunchMode` for checking whether the current platform supports a
given launch mode, to allow clients that will only work with specific modes
to avoid fallback to a different mode.

View File

@ -67,7 +67,7 @@ See [`-[UIApplication canOpenURL:]`](https://developer.apple.com/documentation/u
Add any URL schemes passed to `canLaunchUrl` as `<queries>` entries in your
`AndroidManifest.xml`, otherwise it will return false in most cases starting
on Android 11 (API 30) or higher. Checking for
`supportsLaunchMode(PreferredLaunchMode.inAppBrowserView)` also requires
`supportsLaunchMode(LaunchMode.inAppBrowserView)` also requires
a `<queries>` entry to return anything but false. A `<queries>`
element must be added to your manifest as a child of the root element.
@ -222,9 +222,9 @@ On some platforms, web URLs can be launched either in an in-app web view, or
in the default browser. The default behavior depends on the platform (see
[`launchUrl`](https://pub.dev/documentation/url_launcher/latest/url_launcher/launchUrl.html)
for details), but a specific mode can be used on supported platforms by
passing a `PreferredLaunchMode`.
passing a `LaunchMode`.
Platforms that do no support a requested `PreferredLaunchMode` will
Platforms that do no support a requested `LaunchMode` will
automatically fall back to a supported mode (usually `platformDefault`). If
your application needs to avoid that fallback behavior, however, you can check
if the current platform supports a given mode with `supportsLaunchMode` before

View File

@ -4,7 +4,11 @@
import 'dart:async';
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';
// PreferredLaunchMode is hidden to prevent accidentally using it in APIs at
// this layer. If it is ever needed in this file, it should be imported
// separately with a prefix.
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart'
hide PreferredLaunchMode;
import '../url_launcher_string.dart';
import 'type_conversion.dart';
@ -81,8 +85,8 @@ Future<void> closeInAppWebView() async {
/// Calling [launchUrl] with an unsupported mode will fall back to a supported
/// mode, so calling this method is only necessary for cases where the caller
/// needs to know which mode will be used.
Future<bool> supportsLaunchMode(PreferredLaunchMode mode) {
return UrlLauncherPlatform.instance.supportsMode(mode);
Future<bool> supportsLaunchMode(LaunchMode mode) {
return UrlLauncherPlatform.instance.supportsMode(convertLaunchMode(mode));
}
/// Returns true if [closeInAppWebView] is supported for [mode] in the current
@ -90,6 +94,6 @@ Future<bool> supportsLaunchMode(PreferredLaunchMode mode) {
///
/// If this returns false, [closeInAppWebView] will not work when launching
/// URLs with [mode].
Future<bool> supportsCloseForLaunchMode(PreferredLaunchMode mode) {
return UrlLauncherPlatform.instance.supportsMode(mode);
Future<bool> supportsCloseForLaunchMode(LaunchMode mode) {
return UrlLauncherPlatform.instance.supportsMode(convertLaunchMode(mode));
}

View File

@ -3,7 +3,7 @@ description: Flutter plugin for launching a URL. Supports
web, phone, SMS, and email schemes.
repository: https://github.com/flutter/packages/tree/main/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.2.0
version: 6.2.1
environment:
sdk: ">=3.1.0 <4.0.0"

View File

@ -251,37 +251,35 @@ void main() {
group('supportsLaunchMode', () {
test('handles returning true', () async {
const PreferredLaunchMode mode = PreferredLaunchMode.inAppBrowserView;
mock.setResponse(true);
expect(await supportsLaunchMode(mode), true);
expect(mock.launchMode, mode);
expect(await supportsLaunchMode(LaunchMode.inAppBrowserView), true);
expect(mock.launchMode, PreferredLaunchMode.inAppBrowserView);
});
test('handles returning false', () async {
const PreferredLaunchMode mode = PreferredLaunchMode.inAppBrowserView;
mock.setResponse(false);
expect(await supportsLaunchMode(mode), false);
expect(mock.launchMode, mode);
expect(await supportsLaunchMode(LaunchMode.inAppBrowserView), false);
expect(mock.launchMode, PreferredLaunchMode.inAppBrowserView);
});
});
group('supportsCloseForLaunchMode', () {
test('handles returning true', () async {
const PreferredLaunchMode mode = PreferredLaunchMode.inAppBrowserView;
mock.setResponse(true);
expect(await supportsCloseForLaunchMode(mode), true);
expect(mock.launchMode, mode);
expect(
await supportsCloseForLaunchMode(LaunchMode.inAppBrowserView), true);
expect(mock.launchMode, PreferredLaunchMode.inAppBrowserView);
});
test('handles returning false', () async {
const PreferredLaunchMode mode = PreferredLaunchMode.inAppBrowserView;
mock.setResponse(false);
expect(await supportsCloseForLaunchMode(mode), false);
expect(mock.launchMode, mode);
expect(
await supportsCloseForLaunchMode(LaunchMode.inAppBrowserView), false);
expect(mock.launchMode, PreferredLaunchMode.inAppBrowserView);
});
});
}