url_launcher warns that canLaunch and launch are deprecated
Your error
'canLaunch' is deprecated and shouldn't be used. Use canLaunchUrl instead.2 more lines it can showFix it fast
Most common cause, 1 of 3canLaunch and launch are called with a String URL
Parse the String once into a Uri and call the new functions.
final uri = Uri.parse('https://flutter.dev');
if (await canLaunchUrl(uri)) {
await launchUrl(uri);
}
final mail = Uri(scheme: 'mailto', path: 'support@example.com');
await launchUrl(mail);Short answer
'canLaunch' is deprecated and shouldn't be used. Use canLaunchUrl instead. appears because url_launcher 6.1.0 replaced the String-based canLaunch and launch with canLaunchUrl and launchUrl, which take a Uri. Swap the calls, turn forceSafariVC and forceWebView into a LaunchMode, move JavaScript and header options into WebViewConfiguration, and rename closeWebView to closeInAppWebView. Applies to url_launcher 6.1 to 6.3.3.
Which cause do you have?
List every call to the old API. Plain calls with a String go to the first cause, calls that pass forceSafariVC, forceWebView, enableJavaScript, headers or universalLinksOnly go to the second, and closeWebView goes to the third.
grep -rn -E "\b(canLaunch|launch|closeWebView)\(" lib/Then find the line you see in this list and open its fix:
- 1canLaunch and launch are called with a String URL
deprecated_member_use on canLaunch(url) or launch(url) where url is a String - 2launch() is called with forceSafariVC, forceWebView or web view options
The deprecated launch call passes named arguments that launchUrl does not accept - 3closeWebView() is still used to close an in-app page
deprecated_member_use on closeWebView
What does the error look like?
'canLaunch' is deprecated and shouldn't be used. Use canLaunchUrl instead.'launch' is deprecated and shouldn't be used. Use launchUrl instead.'closeWebView' is deprecated and shouldn't be used. Use closeInAppWebView instead.
Cause 1 of 3
canLaunch and launch are called with a String URL
You seedeprecated_member_use on canLaunch(url) or launch(url) where url is a String
Check
The deprecation warning comes from url_launcher 6.1.0, which introduced canLaunchUrl and launchUrl and marked the String versions deprecated. The new functions take a Uri, which the changelog says prevents common problems with invalid URL strings. The old functions still compile in 6.3.3, and the analyzer flags every use.
dart analyze | grep deprecated_member_useFix
Parse the String once into a Uri and call the new functions. For mailto and tel links, build the Uri from a scheme and a path. launchUrlString exists for the rare address that the host platform accepts but Dart's Uri class rejects.
final uri = Uri.parse('https://flutter.dev');
if (await canLaunchUrl(uri)) {
await launchUrl(uri);
}
final mail = Uri(scheme: 'mailto', path: 'support@example.com');
await launchUrl(mail);Verify
dart analyze no longer reports deprecated_member_use for url_launcher, and the link opens on a device.
dart analyzeConfirmed by pub.dev
Cause 2 of 3
launch() is called with forceSafariVC, forceWebView or web view options
You seeThe deprecated launch call passes named arguments that launchUrl does not accept
Check
launchUrl has no forceSafariVC, forceWebView, universalLinksOnly, enableJavaScript, enableDomStorage or headers parameters, so swapping the function name alone does not compile. Version 6.1.0 replaced the two force flags with a platform-neutral LaunchMode and moved the web view settings into WebViewConfiguration, whose JavaScript and DOM storage now default to enabled instead of disabled.
grep -rn -E "forceSafariVC|forceWebView|universalLinksOnly|enableJavaScript|enableDomStorage" lib/Fix
Pick the LaunchMode that the plugin itself uses for the old flags: inAppWebView for forceWebView: true, inAppBrowserView for forceSafariVC: true (Custom Tabs or SFSafariViewController, url_launcher 6.2.1 and newer), externalNonBrowserApplication for universalLinksOnly: true, and externalApplication otherwise. Pass headers and JavaScript settings through WebViewConfiguration.
// before: launch(url, forceWebView: true, enableJavaScript: true, headers: h)
await launchUrl(
Uri.parse(url),
mode: LaunchMode.inAppWebView,
webViewConfiguration: const WebViewConfiguration(
headers: <String, String>{'Authorization': 'Bearer token'},
),
);
// before: launch(url, forceSafariVC: false)
await launchUrl(Uri.parse(url), mode: LaunchMode.externalApplication);Verify
The page opens in the same place as before (in-app web view, in-app browser or external app) on Android and iOS.
flutter runConfirmed by raw.githubusercontent.com
Cause 3 of 3
closeWebView() is still used to close an in-app page
You seedeprecated_member_use on closeWebView
Check
closeWebView was deprecated in the same 6.1.0 release so that its name says it only works for the in-app web view launch option. It only closes a view that an earlier launch opened in a web view or SafariViewController.
grep -rn "closeWebView" lib/Fix
Call closeInAppWebView instead. It closes a view opened by launchUrl, and only works for a mode where supportsCloseForLaunchMode returns true.
await launchUrl(uri, mode: LaunchMode.inAppWebView);
// later
await closeInAppWebView();Verify
The in-app page closes and the analyzer reports no deprecation.
dart analyzeConfirmed by pub.dev
How do I stop it coming back?
- Run dart analyze in CI with deprecated_member_use left on, so deprecations from plugin upgrades show up in the pull request that causes them.
- Wrap url_launcher in one small helper (openExternal(Uri uri)) so a future API change touches one file instead of every screen.
- After migrating, declare the schemes you query in AndroidManifest.xml and Info.plist, since canLaunchUrl returns false for undeclared schemes on Android 11+ and iOS.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: TaxiDex, Qist Bazaar, SessionBird.