launch method

  1. @override
Future<void> launch(
  1. String url, {
  2. MapType? mapType,
})
override

Launch a URL. Opens in the native app if it handles the URL, otherwise opens in the default browser.

On Android, mapType is used to target the specific app package so the system resolver doesn't open a different app (e.g. Go vs Maps).

Implementation

@override
Future<void> launch(String url, {MapType? mapType}) async {
  final uri = Uri.tryParse(url);
  if (uri == null || !uri.hasScheme) {
    throw ArgumentError.value(url, 'url', 'Invalid URL: must have a scheme');
  }
  final ProcessResult result;
  if (Platform.isMacOS) {
    result = await Process.run('open', [url]);
  } else if (Platform.isWindows) {
    result = await Process.run('cmd', ['/c', 'start', '', url]);
  } else if (Platform.isLinux) {
    result = await Process.run('xdg-open', [url]);
  } else {
    throw UnsupportedError(
      'MapLauncherDesktop does not support ${Platform.operatingSystem}',
    );
  }
  if (result.exitCode != 0) {
    throw Exception('Failed to launch URL: ${result.stderr}');
  }
}