diff --git a/packages/url_launcher/url_launcher/CHANGELOG.md b/packages/url_launcher/url_launcher/CHANGELOG.md index 0f3c087d8f8..db1516640df 100644 --- a/packages/url_launcher/url_launcher/CHANGELOG.md +++ b/packages/url_launcher/url_launcher/CHANGELOG.md @@ -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. diff --git a/packages/url_launcher/url_launcher/README.md b/packages/url_launcher/url_launcher/README.md index 1eeee6da4fe..bb69a52fb91 100644 --- a/packages/url_launcher/url_launcher/README.md +++ b/packages/url_launcher/url_launcher/README.md @@ -67,7 +67,7 @@ See [`-[UIApplication canOpenURL:]`](https://developer.apple.com/documentation/u Add any URL schemes passed to `canLaunchUrl` as `` 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 `` entry to return anything but false. A `` 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 diff --git a/packages/url_launcher/url_launcher/lib/src/url_launcher_uri.dart b/packages/url_launcher/url_launcher/lib/src/url_launcher_uri.dart index 06262165693..23ea836b740 100644 --- a/packages/url_launcher/url_launcher/lib/src/url_launcher_uri.dart +++ b/packages/url_launcher/url_launcher/lib/src/url_launcher_uri.dart @@ -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 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 supportsLaunchMode(PreferredLaunchMode mode) { - return UrlLauncherPlatform.instance.supportsMode(mode); +Future 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 supportsLaunchMode(PreferredLaunchMode mode) { /// /// If this returns false, [closeInAppWebView] will not work when launching /// URLs with [mode]. -Future supportsCloseForLaunchMode(PreferredLaunchMode mode) { - return UrlLauncherPlatform.instance.supportsMode(mode); +Future supportsCloseForLaunchMode(LaunchMode mode) { + return UrlLauncherPlatform.instance.supportsMode(convertLaunchMode(mode)); } diff --git a/packages/url_launcher/url_launcher/pubspec.yaml b/packages/url_launcher/url_launcher/pubspec.yaml index 7546e6bf7de..5947671ffea 100644 --- a/packages/url_launcher/url_launcher/pubspec.yaml +++ b/packages/url_launcher/url_launcher/pubspec.yaml @@ -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" diff --git a/packages/url_launcher/url_launcher/test/src/url_launcher_uri_test.dart b/packages/url_launcher/url_launcher/test/src/url_launcher_uri_test.dart index 0e6e76c38ea..0c5bfdcf247 100644 --- a/packages/url_launcher/url_launcher/test/src/url_launcher_uri_test.dart +++ b/packages/url_launcher/url_launcher/test/src/url_launcher_uri_test.dart @@ -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); }); }); }