A Flutter plugin for launching a URL in the mobile platform. Supports iOS and Android.
To use this plugin, add url_launcher
as a dependency in your pubspec.yaml file.
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
void main() {
runApp(Scaffold(
body: Center(
child: RaisedButton(
onPressed: _launchURL,
child: Text('Show Flutter homepage'),
),
),
));
}
_launchURL() async {
const url = 'https://flutter.io';
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
The launch
method
takes a string argument containing a URL. This URL
can be formatted using a number of different URL schemes. The supported
URL schemes depend on the underlying platform and installed apps.
Common schemes supported by both iOS and Android:
Scheme | Action |
---|---|
http:<URL> , https:<URL> , e.g. http://flutter.io | Open URL in the default browser |
mailto:<email address>?subject=<subject>&body=<body> , e.g. mailto:smith@example.org?subject=News&body=New%20plugin | Create email to <email address> in the default email app |
tel:<phone number> , e.g. tel:+1 555 010 999 | Make a phone call to <phone number> using the default phone app |
sms:<phone number> , e.g. sms:5550101234 | Send an SMS message to <phone number> using the default messaging app |
More details can be found here for iOS and Android
A particular mobile device may not be able to receive all supported URL schemes.
For example, a tablet may not have a cellular radio and thus no support for
launching a URL using the sms
scheme, or a device may not have an email app
and thus no support for launching a URL using the email
scheme.
We recommend checking which URL schemes are supported using the
canLaunch
method prior to calling launch
. If the canLaunch
method returns false, as a
best practice we suggest adjusting the application UI so that the unsupported
URL is never triggered; for example, if the email
scheme is not supported, a
UI button that would have sent email can be changed to redirect the user to a
web page using a URL following the http
scheme.
By default, Android opens up a browser when handling URLs. You can pass forceWebView: true parameter to tell the plugin to open a WebView instead. On iOS, the default behavior is to open all web URLs within the app. Everything else is redirected to the app handler.
Breaking change. Migrate from the deprecated original Android Support Library to AndroidX. This shouldn't result in any functional changes, but it requires any Android apps using this plugin to also migrate if they're using the original support library.
This was originally incorrectly pushed in the 4.2.0
update.
5.0.0
instead. That's the correctly versioned new push
of 4.2.0
.launch
to use async and await, fixed the incorrect return value by launch
method.BAD. This was a breaking change that was incorrectly published on a minor version upgrade, should never have happened. Reverted by 4.2.0+3.
Breaking change. Migrate from the deprecated original Android Support Library to AndroidX. This shouldn't result in any functional changes, but it requires any Android apps using this plugin to also migrate if they're using the original support library.
universalLinksOnly
setting.launch
to return Future<bool>
.launch
now assert activity not null and using activity to startActivity.WebViewActivity has leaked IntentReceiver
for Android.closeWebView
function to programmatically close the current WebView.launch
to enable javascript in Android WebView.launch
to set iOS status bar brightness.launch
now returns Future<void>
instead of
Future<Null>
.canLaunch
method.launch
to a top-level method instead of a static method in a class.example/README.md
Demonstrates how to use the url_launcher plugin.
For help getting started with Flutter, view our online documentation.
Add this to your package's pubspec.yaml file:
dependencies:
url_launcher: ^5.0.1
You can install packages from the command line:
with Flutter:
$ flutter packages get
Alternatively, your editor might support flutter packages get
.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:url_launcher/url_launcher.dart';
Version | Uploaded | Documentation | Archive |
---|---|---|---|
5.0.1 | Feb 8, 2019 |
|
|
5.0.0 | Jan 28, 2019 |
|
|
4.2.0+3 | Jan 28, 2019 |
|
|
4.2.0+2 | Jan 28, 2019 |
|
|
4.2.0+1 | Jan 25, 2019 |
|
|
4.2.0 | Jan 24, 2019 |
|
|
4.1.0+1 | Jan 23, 2019 |
|
|
4.1.0 | Jan 23, 2019 |
|
|
4.0.3 | Dec 21, 2018 |
|
|
4.0.2 | Nov 26, 2018 |
|
|
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
100
|
Health:
Code health derived from static analysis.
[more]
|
100
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
100
|
Overall:
Weighted score of the above.
[more]
|
100
|
We analyzed this package on Feb 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Detected platforms: Flutter
References Flutter, and has no conflicting libraries.
Package | Constraint | Resolved | Available |
---|---|---|---|
Direct dependencies | |||
Dart SDK | >=2.0.0-dev.28.0 <3.0.0 | ||
flutter | 0.0.0 | ||
Transitive dependencies | |||
collection | 1.14.11 | ||
meta | 1.1.6 | 1.1.7 | |
sky_engine | 0.0.99 | ||
typed_data | 1.1.6 | ||
vector_math | 2.0.8 | ||
Dev dependencies | |||
flutter_test |