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.

Uses the platform-appropriate command:

  • macOS: open <url>
  • Linux: xdg-open <url>
  • Windows: cmd /c start "" <url>
Cmd.openUrl(
  'https://example.com',
  onComplete: (result) => BrowserOpenedMsg(),
)

Implementation

static Cmd openUrl(
  String url, {
  required Msg Function(ExecResult result) onComplete,
}) {
  final executable = io.Platform.isMacOS
      ? 'open'
      : io.Platform.isWindows
      ? 'cmd'
      : 'xdg-open';
  final arguments = io.Platform.isWindows ? ['/c', 'start', '', url] : [url];
  return exec(executable, arguments, onComplete: onComplete);
}