How to Open Web URL From Flutter Code ?

· 2 min read
How to Open Web URL From Flutter Code
How to Open Web URL From Flutter Code

While Building a Flutter Mobile Application some time user needs to redirect to the Web URL so in this article We will go through How to Open Web URL From Flutter Code?

How to Open Web URL From Flutter Code?

T Open URL follow the instruction as below:

Using the URL Launcher plugin url_launcher

  • In pubspec.yaml
dependencies:
  url_launcher: ^5.4.2
  • Import package like below:
import 'package:url_launcher/url_launcher.dart';

To launching a web page, Let’s be an async function and do the following:

launchURL(String url) async {
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not launch $url';
    }
  }

If we wanted both iOS and Android to open the web page inside the application (as a WebView), then add forceWebView: true we’d do something like this:

launchURL(String url) async {
    if (await canLaunch(url)) {
      await launch(url, forceWebView: true);
    } else {
      throw 'Could not launch $url';
    }
 }

And call it this way

onTap: () {
    const url = 'https://google.com';
    launchURL(url);
}

We will get output like below:

"<yoastmark

For Flutter Web:

import 'dart:html' as html;

Then use:

html.window.open(url, name);

Make sure that you run Flutter clean if the import doesn’t resolve.

Conclusion:

In this article, We have been through How to Open Web URL  From Flutter Code?

Keep Learning !!!
Keep Fluttering.

FlutterAgency.com is our portal Platform dedicated to Flutter Technology and Flutter Developers. The portal is full of cool resources from Flutter like Flutter Widget GuideFlutter ProjectsCode libs and etc.

FlutterAgency.com is one of the most popular online portal dedicated to Flutter Technology and daily thousands of unique visitors come to this portal to enhance their knowledge on Flutter.

Leave a Reply