downloadAndInstall method

  1. @override
Future<void> downloadAndInstall({
  1. required String url,
  2. required String fileName,
  3. Map<String, String> headers = const {},
  4. String? sha256,
  5. void onProgress(
    1. int received,
    2. int total
    )?,
})
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);
  }
}