url_launcher 1.0.3

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 100

url_launcher

pub package

A Flutter plugin for launching a URL in the mobile platform. Supports iOS and Android.

Usage

To use this plugin, add url_launcher as a dependency in your pubspec.yaml file.

Example

import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

void main() {
  runApp(new Scaffold(
    body: new Center(
      child: new RaisedButton(
        onPressed: _launchURL,
        child: new Text('Show Flutter homepage'),
      ),
    ),
  ));
}

_launchURL() async {
  const url = 'https://flutter.io';
  if (await canLaunch(url)) {
    await launch(url);
  } else {
    throw 'Could not launch $url';
  }
}

Supported URL schemes

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:

SchemeAction
http:<URL> , https:<URL>, e.g. http://flutter.ioOpen URL in the default browser
mailto:<email address>?subject=<subject>&body=<body>, e.g. mailto:smith@example.org?subject=News&body=New%20pluginCreate email to <email address> in the default email app
tel:<phone number>, e.g. tel:+1 555 010 999Make a phone call to <phone number> using the default phone app
sms:<phone number>, e.g. sms:5550101234Send an SMS message to <phone number> using the default messaging app

More details can be found here for iOS and Android

Handling missing URL receivers

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.

Browser vs In-app Handling

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.

1.0.3

  • Add FLT prefix to iOS types.

1.0.2

  • Fix handling of URLs in Android WebView.

1.0.1

  • Support option to launch default browser in iOS.
  • Parse incoming url and decide on what to open based on scheme.
  • Support WebView on Android.

1.0.0

  • iOS plugin presents a Safari view controller instead of switching to the Safari app.

0.4.2+5

  • Aligned author name with rest of repo.

[0.4.2+2], [0.4.2+3], [0.4.2+4] - 2017-08-16

  • Updated README.

[0.4.2+1] - 2017-05-16

  • Updated README.

[0.4.2] - 2017-05-15

  • Change to README.md.

[0.4.1] - 2017-05-09

  • Upgrade Android SDK Build Tools to 25.0.3.

[0.4.0] - 2017-05-09

  • Upgrade to new plugin registration.

[0.3.6] - 2017-05-09

  • Fix workaround for failing dynamic check in Xcode 7/sdk version 9.

[0.3.5] - 2017-05-08

  • Workaround for failing dynamic check in Xcode 7/sdk version 9.

[0.3.4] - 2017-05-08

  • Add test.

[0.3.3] - 2017-05-05

  • Change to buildToolsVersion.

[0.3.2] - 2017-05-04

  • Change to README.md.

[0.3.1] - 2017-05-01

  • Change to README.md.

[0.3.0] - 2017-04-27

  • Add canLaunch method.

[0.2.0] - 2017-04-24

  • Change launch to a top-level method instead of a static method in a class.

[0.1.1] - 2017-04-21

  • Change to README.md.

[0.1.0] - 2017-04-20

  • Initial Open Source release.

example/lib/main.dart

// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

void main() {
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'URL Launcher',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(title: 'URL Launcher'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Future<Null> _launched;

  Future<Null> _launchInBrowser(String url) async {
    if (await canLaunch(url)) {
      await launch(url, forceSafariVC: false, forceWebView: false);
    } else {
      throw 'Could not launch $url';
    }
  }

  Future<Null> _launchInWebViewOrVC(String url) async {
    if (await canLaunch(url)) {
      await launch(url, forceSafariVC: true, forceWebView: true);
    } else {
      throw 'Could not launch $url';
    }
  }

  Widget _launchStatus(BuildContext context, AsyncSnapshot<Null> snapshot) {
    if (snapshot.hasError) {
      return new Text('Error: ${snapshot.error}');
    } else {
      return const Text('');
    }
  }

  @override
  Widget build(BuildContext context) {
    const String toLaunch = 'https://flutter.io';
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: new Center(
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Padding(
              padding: const EdgeInsets.all(16.0),
              child: const Text(toLaunch),
            ),
            new RaisedButton(
              onPressed: () => setState(() {
                    _launched = _launchInBrowser(toLaunch);
                  }),
              child: const Text('Launch in browser'),
            ),
            const Padding(padding: const EdgeInsets.all(16.0)),
            new RaisedButton(
              onPressed: () => setState(() {
                    _launched = _launchInWebViewOrVC(toLaunch);
                  }),
              child: const Text('Launch in app'),
            ),
            const Padding(padding: const EdgeInsets.all(16.0)),
            new FutureBuilder<Null>(future: _launched, builder: _launchStatus),
          ],
        ),
      ),
    );
  }
}

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  url_launcher: "^1.0.3"

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:url_launcher/url_launcher.dart';
        
Version Uploaded Documentation Archive
1.0.3 Dec 4, 2017 Go to the documentation of url_launcher 1.0.3 Download url_launcher 1.0.3 archive
1.0.2 Nov 29, 2017 Go to the documentation of url_launcher 1.0.2 Download url_launcher 1.0.2 archive
1.0.1 Nov 18, 2017 Go to the documentation of url_launcher 1.0.1 Download url_launcher 1.0.1 archive
0.4.2+5 Sep 20, 2017 Go to the documentation of url_launcher 0.4.2+5 Download url_launcher 0.4.2+5 archive
0.4.2+4 Aug 16, 2017 Go to the documentation of url_launcher 0.4.2+4 Download url_launcher 0.4.2+4 archive
0.4.2+3 Aug 16, 2017 Go to the documentation of url_launcher 0.4.2+3 Download url_launcher 0.4.2+3 archive
0.4.2+2 Aug 16, 2017 Go to the documentation of url_launcher 0.4.2+2 Download url_launcher 0.4.2+2 archive
0.4.2+1 May 17, 2017 Go to the documentation of url_launcher 0.4.2+1 Download url_launcher 0.4.2+1 archive
0.4.2 May 15, 2017 Go to the documentation of url_launcher 0.4.2 Download url_launcher 0.4.2 archive
0.4.1 May 9, 2017 Go to the documentation of url_launcher 0.4.1 Download url_launcher 0.4.1 archive

All 21 versions...

Analysis

This feature is new.
We welcome feedback.

We analyzed this package, and provided a score, details, and suggestions below.

  • completed on Dec 6, 2017
  • Dart: 2.0.0-dev.8.0
  • pana: 0.7.3+1
  • Flutter: 0.0.19

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
99
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall score:
Weighted score of the above. [more]
100

Platforms

Detected platforms: Flutter

pubspec reference with no conflicts

Dependencies

Package Constraint Resolved Available
Direct dependencies
flutter 0.0.39
Transitive dependencies
async 1.13.3 2.0.1
charcode 1.1.1
collection 1.14.3
http 0.11.3+14 0.11.3+16
http_parser 3.1.1
meta 1.1.1 1.1.2
path 1.5.1
sky_engine 0.0.99
source_span 1.4.0
stack_trace 1.9.1
string_scanner 1.0.2
typed_data 1.1.4 1.1.5
vector_math 2.0.5
Dev dependencies
flutter_test