downloadAndInstall method
Future<void>
downloadAndInstall({
- required String url,
- required String fileName,
- Map<
String, String> headers = const {}, - String? sha256,
- void onProgress()?,
override
Downloads url to fileName, verifies it against sha256 when given,
and opens the system installer. Completes once the installer is shown.
Implementation
@override
Future<void> downloadAndInstall({
required String url,
required String fileName,
Map<String, String> headers = const {},
String? sha256,
void Function(int received, int total)? onProgress,
}) async {
methodChannel.setMethodCallHandler((call) async {
if (call.method == 'progress') {
final args = call.arguments as Map;
onProgress?.call(args['received'] as int, args['total'] as int);
}
});
try {
await methodChannel.invokeMethod<void>('downloadAndInstall', {
'url': url,
'fileName': fileName,
'headers': headers,
'sha256': sha256,
});
} on PlatformException catch (e) {
throw OtaException(e.code, e.message);
} on MissingPluginException {
throw _unsupported;
} finally {
methodChannel.setMethodCallHandler(null);
}
}