openUrl static method

Cmd openUrl(
  1. String url, {
  2. required Msg onComplete(
    1. ExecResult result
    ),
})

A command that opens a URL in the default browser.

Cmd.openUrl(
  'https://example.com',
  onComplete: (result) => BrowserOpenedMsg(),
)

Implementation

static Cmd openUrl(
  String url, {
  required Msg Function(ExecResult result) onComplete,
}) {
  final String command;
  final List<String> args;

  if (io.Platform.isMacOS) {
    command = 'open';
    args = [url];
  } else if (io.Platform.isWindows) {
    command = 'cmd';
    args = ['/c', 'start', '', url];
  } else {
    // Linux and other Unix-like systems
    command = 'xdg-open';
    args = [url];
  }

  return exec(command, args, onComplete: onComplete);
}