Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I open an external url in flutter web in new tab or in same tab

I have a simple web app I have created with flutter web. I would like to know how I can open new an external url either in a new tab or in the same tab in my flutter web app. say I want to open the url https://stackoverflow.com/questions/ask

like image 229
Norbert Avatar asked May 20 '19 12:05

Norbert


People also ask

How do I navigate to a website in Flutter?

Here, we have two pages, FIRST_PAGE (Example: localhost:3000/#/first_page) and SECOND_PAGE (Example: localhost:3000/#/second_page). Now, we will create a reusable onGenerateRoute class in our second routes file. Using the route settings, we will get the Routes name and then navigate to the corresponding Page.

How do you add a hyperlink button on Flutter?

linkify Flutter plugin can turn text URL and email to a clickable inline text. First, add flutter_linkify plugin to your project. Next import to the file which you are going to implement the code. print("Linkify link = ${link.


2 Answers

I think you want this — dart:js enables interoperability between Dart and JS —:

import 'dart:js' as js;  // ...  FlatButton(   child: Text('Button'),   onPressed: () {     js.context.callMethod('open', ['https://stackoverflow.com/questions/ask']);   }, ) 
like image 83
xuyanjun Avatar answered Sep 22 '22 04:09

xuyanjun


One simple way is to just create a button and use dart:html's window.open() method:

import 'dart:html' as html;  // ...  html.window.open('https://stackoverflow.com/questions/ask', 'new tab'); 

The name parameter — which I left as 'new tab' — refers to the new tab's window name, about which you can learn more from MDN's documentation.

like image 34
Philippe Fanaro Avatar answered Sep 20 '22 04:09

Philippe Fanaro