-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[url_launcher] Replace primary APIs with cleaner versions #5310
[url_launcher] Replace primary APIs with cleaner versions #5310
Conversation
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is actually just a move of the old url_launcher.dart
, unchanged.
This looks fantastic, let me do a proper review tomorrow!! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with only a couple of comments.
* replace `forceSafariVC` and `forceWebView` with `LaunchMode`, which makes | ||
the API platform-neutral, and standardizes the default behavior between | ||
Android and iOS. | ||
* move web view configuration options into a new `WebViewConfiguration` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is changing the default setting not a braking change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case the old API with the old config style is still available. You only need to migrate to the WebViewConfiguration
if you start using the new URI/String based APIs (not the one under legacy
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the new approach very much, some minor comments/nits/praise below.
For example, UI button that would have sent feedback email using a `mailto` URL | ||
might instead open a web-based feedback form using an `https` URL on failure, | ||
rather than disabling the button if `canLaunchUrl` returns false for `mailto`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent suggestion.
and thus no support for launching a URL using the `mailto` scheme. | ||
In rare cases, you may need to launch a URL that the host system considers | ||
valid, but cannot be expressed by `Uri`. For those cases, alternate APIs using | ||
strings are available by importing `url_launcher_string.dart`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we take a page from the React book and call this file: dangerous_url_launcher_string.dart
or similar, so users that import this get scared?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did think about it; my hope is that having to find a separate import is already enough of a deterrent.
If that turns out not to be true and we see a lot of people filing issue because they blindly used this and ignored all the warnings about how it should rarely be used, we could deprecate that import file and add one with a scary name.
packages/url_launcher/url_launcher/lib/url_launcher_string.dart
Outdated
Show resolved
Hide resolved
Co-authored-by: Maurice Parrish <[email protected]>
Co-authored-by: David Iglesias <[email protected]>
This deprecates the existing APIs in favor of versions that:
Uri
instead ofString
, to avoid a very common class of errorsLaunchMode
optionurl_launcher
is likely to be used as a browser, so should have browser-like defaults of supporting things like JavaScript)See flutter/flutter#79043 for background.
New
String
-based versions (which are otherwise consistent with theUri
versions) are provided for a rare edge case we've seen in the past, but are separated into a separate file that is notexport
ed to prevent accidental use due to autocomplete, since they are a foot-gun.Also reworks the README, including:
canLaunchUrl
that reflects the realities of platforms like web (and more generally, the fact that usingcanLaunchUrl
+launchUrl
is often worse than justlaunchUrl
+fallback).Fixes flutter/flutter#79043
Closes flutter/flutter#51471
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.