Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the current operating system's default browser & open a web page with it?

Tags:

dart

With a local client side application, with

import 'dart:io';

I see no way to load up the consumers current default browser and then load a web page. (Locally stored HTML or a website)

I've searched the API documentation at http://api.dartlang.org yet have found no easy way.

Is there any way of doing this yet? Preferably similar to the Desktop class in java ?

like image 251
Mourner63 Avatar asked Dec 12 '12 17:12

Mourner63


1 Answers

I don't think there's a function for that. You can fill a new feature request.

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

  • on Windows you should be able to launch the default browser with start ${url}.
  • on linux, you can do that with xdg-open ${url} if xdg-open is present.
  • in other cases, there should be a solution...

Here is a sample :

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]);
  }
}
like image 147
Alexandre Ardhuin Avatar answered Nov 02 '22 16:11

Alexandre Ardhuin