updateApp static method
Implementation
static Future<void> updateApp({Function(int start, int total)? onProgress, Function? onDownloaded, Function? onInstalled, Function? onFailed}) async {
if (Platform.isAndroid) {
updateStream = StreamController();
await _channel.invokeMethod('update');
_startListener();
updateStream!.stream.listen((event) {
if (event == 'DOWNLOADED') {
if (onDownloaded != null) {
onDownloaded();
}
} else if (event == 'INSTALLED') {
if (onInstalled != null) {
onInstalled();
}
updateStream!.close();
updateStream = null;
} else if (event == 'FAILED') {
if (onFailed != null) {
onFailed();
}
updateStream!.close();
updateStream = null;
} else if (event.toString().contains('|')) {
final parse = event.toString().split('|');
if (onProgress != null) {
try {
onProgress(int.tryParse(parse[0]) ?? 0, int.tryParse(parse[1]) ?? 0);
} catch (_) {
onProgress(0, 0);
}
}
}
});
}
}