runUpdate method
Install/navigate to the respective file on OS
iOS: Launch URL(App Store Url Scheme)
Android: apk
Windows: exe/msix
Application/Installer/App Store uri
autoExit
parent process, only applies to Windows
Implementation
Future<void> runUpdate(FilePath uri,
{bool autoExit = false, int exitDelay = 3000}) async {
if (Platform.isIOS) {
await canLaunch(downloadUrl)
? await launch(downloadUrl)
: throw Exception("Fail to launch App Store url");
} else if (Platform.isAndroid) {
await AppInstaller.installApk(uri);
} else if (Platform.isWindows) {
// Start the process using Windows shell instead of our parent process.
// A detached process has no connection to its parent,
// and can keep running on its own when the parent dies
try {
await Process.start(uri, [],
runInShell: true, mode: ProcessStartMode.detached);
if (autoExit) {
await Future.delayed(Duration(milliseconds: exitDelay));
exit(0);
}
} on Exception catch (e) {
throw Exception("Failed to execute the file. Error: $e");
}
} else {
throw Exception("Platform not supported");
}
}