Open Link in Flutter

url_launcher  is an official Flutter plugin for launching a URL in iOS, Android, web, Windows, macOS, and Linux.

List of common schemes supported on mobile:

http:<URL> , https:<URL>, e.g. https://www.tldevtech.comOpen the URL in the default browser
mailto:<email address>?subject=<subject>&body=<body>, e.g. mailto:[email protected]?subject=Contact&body=New%20pluginCreate email to
tel:<phone number>, e.g. tel:+1 555 111 222Make a phone call to
sms:<phone number>, e.g. sms:5552223334Send an SMS message to

Despite its support for the web, you can’t use it properly yet in Flutter for the Web in the beta channel. We need to detect the current platform and provide a suitable solution.

Required packages:

import 'dart:html' as html;
import 'dart:io';
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

Create a function to open an URL based on the current platform

void _launchUrl(String url) async {

    if (kIsWeb) {     // web
      html.document.window.location.href = url;
    } else if (Platform.isAndroid || Platform.isIOS || Platform.isFushsia || Platform.isWindows) {
      // others
      if (await canLaunch(url)) {
        await launch(url);
      } else {
        throw 'Could not launch $url';
    } else {
      // the rest
      throw new Exception('Unsupported platform');

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.