Get the current default operating system browser and open a web page with it?

In a local client application with

import 'dart:io'; 

I do not see the ability to load the current default browser, and then load the web page. (Locally stored HTML or website)

I searched the API documentation at http://api.dartlang.org but did not find an easy way.

Is there any way to do this? Preferably, similar to the Desktop class in java ?

+8
dart
source share
2 answers

I do not think there is a function for this. You can fill out a new feature request .

If you need a workaround, you can deal with Process and Platform .

  • on Windows, you can start the default browser using start ${url} .
  • on linux you can do this with xdg-open ${url} if xdg-open present.
  • in other cases there must be a solution ...

Here is an example:

 import 'dart:io'; main() { final url = "http://dartlang.org"; if (Platform.operatingSystem == 'windows') { Process.run("start", [url]); } else if (Platform.operatingSystem == 'linux') { Process.run("xdg-open", [url]); } } 
+5
source share

On Windows, I found that the runInShell flag must be set:

 Process.run("start", [url], runInShell: true); 

(at least on Windows 7).

I am surprised that someone did not create a package to reliably call the default browser on all platforms.

0
source share

All Articles