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?

Time needed: 3 minutes.
Follow All Step To Open a web Browser in flutter
- 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 - Get dependencies by flutter pub get
Get dependencies by flutter pub get
- Import it
Now in your Dart code, you can use:
import 'package:url_launcher/url_launcher.dart';
- 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’;
}
} - 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';
}
}
- 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 - 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.
Leave a Reply