Skip to content

Commit fea24c5

Browse files
[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 flutter/flutter#137278
1 parent f2124f7 commit fea24c5

File tree

5 files changed

+30
-21
lines changed

5 files changed

+30
-21
lines changed

packages/url_launcher/url_launcher/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
## 6.2.1
2+
3+
* Fixes incorrect types in `supportsLaunchMode` and
4+
`supportsCloseForLaunchMode`.
5+
16
## 6.2.0
27

8+
_Retracted due to incorrect types in new APIs._
9+
310
* Adds `supportsLaunchMode` for checking whether the current platform supports a
411
given launch mode, to allow clients that will only work with specific modes
512
to avoid fallback to a different mode.

packages/url_launcher/url_launcher/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ See [`-[UIApplication canOpenURL:]`](https://developer.apple.com/documentation/u
6767
Add any URL schemes passed to `canLaunchUrl` as `<queries>` entries in your
6868
`AndroidManifest.xml`, otherwise it will return false in most cases starting
6969
on Android 11 (API 30) or higher. Checking for
70-
`supportsLaunchMode(PreferredLaunchMode.inAppBrowserView)` also requires
70+
`supportsLaunchMode(LaunchMode.inAppBrowserView)` also requires
7171
a `<queries>` entry to return anything but false. A `<queries>`
7272
element must be added to your manifest as a child of the root element.
7373

@@ -222,9 +222,9 @@ On some platforms, web URLs can be launched either in an in-app web view, or
222222
in the default browser. The default behavior depends on the platform (see
223223
[`launchUrl`](https://pub.dev/documentation/url_launcher/latest/url_launcher/launchUrl.html)
224224
for details), but a specific mode can be used on supported platforms by
225-
passing a `PreferredLaunchMode`.
225+
passing a `LaunchMode`.
226226

227-
Platforms that do no support a requested `PreferredLaunchMode` will
227+
Platforms that do no support a requested `LaunchMode` will
228228
automatically fall back to a supported mode (usually `platformDefault`). If
229229
your application needs to avoid that fallback behavior, however, you can check
230230
if the current platform supports a given mode with `supportsLaunchMode` before

packages/url_launcher/url_launcher/lib/src/url_launcher_uri.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
import 'dart:async';
66

7-
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';
7+
// PreferredLaunchMode is hidden to prevent accidentally using it in APIs at
8+
// this layer. If it is ever needed in this file, it should be imported
9+
// separately with a prefix.
10+
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart'
11+
hide PreferredLaunchMode;
812

913
import '../url_launcher_string.dart';
1014
import 'type_conversion.dart';
@@ -81,15 +85,15 @@ Future<void> closeInAppWebView() async {
8185
/// Calling [launchUrl] with an unsupported mode will fall back to a supported
8286
/// mode, so calling this method is only necessary for cases where the caller
8387
/// needs to know which mode will be used.
84-
Future<bool> supportsLaunchMode(PreferredLaunchMode mode) {
85-
return UrlLauncherPlatform.instance.supportsMode(mode);
88+
Future<bool> supportsLaunchMode(LaunchMode mode) {
89+
return UrlLauncherPlatform.instance.supportsMode(convertLaunchMode(mode));
8690
}
8791

8892
/// Returns true if [closeInAppWebView] is supported for [mode] in the current
8993
/// platform implementation.
9094
///
9195
/// If this returns false, [closeInAppWebView] will not work when launching
9296
/// URLs with [mode].
93-
Future<bool> supportsCloseForLaunchMode(PreferredLaunchMode mode) {
94-
return UrlLauncherPlatform.instance.supportsMode(mode);
97+
Future<bool> supportsCloseForLaunchMode(LaunchMode mode) {
98+
return UrlLauncherPlatform.instance.supportsMode(convertLaunchMode(mode));
9599
}

packages/url_launcher/url_launcher/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for launching a URL. Supports
33
web, phone, SMS, and email schemes.
44
repository: https://github.com/flutter/packages/tree/main/packages/url_launcher/url_launcher
55
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+url_launcher%22
6-
version: 6.2.0
6+
version: 6.2.1
77

88
environment:
99
sdk: ">=3.1.0 <4.0.0"

packages/url_launcher/url_launcher/test/src/url_launcher_uri_test.dart

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -251,37 +251,35 @@ void main() {
251251

252252
group('supportsLaunchMode', () {
253253
test('handles returning true', () async {
254-
const PreferredLaunchMode mode = PreferredLaunchMode.inAppBrowserView;
255254
mock.setResponse(true);
256255

257-
expect(await supportsLaunchMode(mode), true);
258-
expect(mock.launchMode, mode);
256+
expect(await supportsLaunchMode(LaunchMode.inAppBrowserView), true);
257+
expect(mock.launchMode, PreferredLaunchMode.inAppBrowserView);
259258
});
260259

261260
test('handles returning false', () async {
262-
const PreferredLaunchMode mode = PreferredLaunchMode.inAppBrowserView;
263261
mock.setResponse(false);
264262

265-
expect(await supportsLaunchMode(mode), false);
266-
expect(mock.launchMode, mode);
263+
expect(await supportsLaunchMode(LaunchMode.inAppBrowserView), false);
264+
expect(mock.launchMode, PreferredLaunchMode.inAppBrowserView);
267265
});
268266
});
269267

270268
group('supportsCloseForLaunchMode', () {
271269
test('handles returning true', () async {
272-
const PreferredLaunchMode mode = PreferredLaunchMode.inAppBrowserView;
273270
mock.setResponse(true);
274271

275-
expect(await supportsCloseForLaunchMode(mode), true);
276-
expect(mock.launchMode, mode);
272+
expect(
273+
await supportsCloseForLaunchMode(LaunchMode.inAppBrowserView), true);
274+
expect(mock.launchMode, PreferredLaunchMode.inAppBrowserView);
277275
});
278276

279277
test('handles returning false', () async {
280-
const PreferredLaunchMode mode = PreferredLaunchMode.inAppBrowserView;
281278
mock.setResponse(false);
282279

283-
expect(await supportsCloseForLaunchMode(mode), false);
284-
expect(mock.launchMode, mode);
280+
expect(
281+
await supportsCloseForLaunchMode(LaunchMode.inAppBrowserView), false);
282+
expect(mock.launchMode, PreferredLaunchMode.inAppBrowserView);
285283
});
286284
});
287285
}

0 commit comments

Comments
 (0)