close
open a web browser url in flutter, open a web browser flutter, web browser url flutter, open a web browser (URL) from Flutter code

How to open a web browser (URL) from Flutter code?

Hello Guys. Many times we need to open some hyperlinks in the flutter project. So in this tutorial, we are going to learn How to open a web browser (URL) from my Flutter code?

Without Wasting Your Time Lets Start This Article.

How to open a web browser (URL) from Flutter code?

open a web browser url in flutter, open a web browser flutter, web browser url flutter, open a web browser (URL) from Flutter code

Time needed: 3 minutes.

Follow All Step To Open a web Browser in flutter

  1. Install Flutter Plugin

    All of we need is to install url_launcher package in our project. Define below line in your pubspec.yaml file.

    url_launcher: ^5.4.2

    How do I open a web browser (URL) from my Flutter code?

  2. Get dependencies by flutter pub get

    Get dependencies by flutter pub get

  3. Import it

    Now in your Dart code, you can use:
    import 'package:url_launcher/url_launcher.dart';
    How do I open a web browser (URL) from my Flutter code?

  4. Now We are ready to use this plugin

    Follow Below Code to open URL in browser

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

  5. That’s It

    Now You can call this method to open your browser.

Here is my main.dart full source code for batter understanding.

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';
  }
}
  1. How to open a web browser (URL) from Flutter code?

    to open a web browser (URL) from Flutter code
    All of we need is to install url_launcher package in our project. Define below line in your pubspec.yaml file.
    Get dependencies by flutter pub get
    Now in your Dart code, you can use: import 'package:url_launcher/url_launcher.dart';
    Follow Below Code to open URL in browser

  2. open a web browser (URL) from Flutter code

    to open a web browser (URL) from Flutter code
    All of we need is to install url_launcher package in our project. Define below line in your pubspec.yaml file.
    Get dependencies by flutter pub get
    Now in your Dart code, you can use: import 'package:url_launcher/url_launcher.dart';
    Follow Below Code to open URL in browser

Summery

So, It’s All About This tutorial. I hope this tutorial helps you lot. Please Comment Below if You stucks anywhere with my code. Thank You.

Also Check Out Below Tutorials

Comments

Leave a Reply

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