openUrl function
Open the URL in the default browser.
Implementation
Future<ProcessResult> openUrl(String url) {
String command() {
if (Platform.isWindows) {
return 'start';
} else if (Platform.isLinux) {
return 'xdg-open';
} else if (Platform.isMacOS) {
return 'open';
} else {
throw UnsupportedError('Operating system not supported by the open_url '
'package: ${Platform.operatingSystem}');
}
}
if (Platform.isWindows) {
/// This is needed because ampersand has to be escaped with carret on Windows shell,
/// otherwise opened URL will be trimmed by first ampersand
url = url.replaceAllMapped(RegExp('([^^])&'), (Match m) => '${m[1]}^&');
}
return Process.run(command(), <String>[url], runInShell: true);
}