openBrowser function
Opens url in the user's default browser.
Uses open on macOS, xdg-open on Linux, and start on Windows. Returns
true when the launch command was invoked (not whether the browser actually
opened).
Implementation
Future<bool> openBrowser(String url) async {
String executable;
List<String> args;
if (Platform.isMacOS) {
executable = 'open';
args = [url];
} else if (Platform.isLinux) {
executable = 'xdg-open';
args = [url];
} else if (Platform.isWindows) {
executable = 'start';
args = ['', url];
} else {
return false;
}
try {
final result = await Process.run(executable, args);
return result.exitCode == 0;
} on Object {
return false;
}
}