US Office

1176 Shadeville Rd, Crawfordville Florida 32327, USA

 +1 (850) 780-1313

India Office

Office No 405, Kabir Shilp, Opp. Kansar Hotel, Opp. Landmark, Kudasan, Gandhinagar, Gujarat 382421

[email protected]

How to Open Web URL From Flutter Code?

How to Open Web URL From Flutter Code

How to Open Web URL From Flutter Code?

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.

Post a Comment