downloadAndInstallApk method

  1. @override
Future<void> downloadAndInstallApk({
  1. required String downloadFileUrl,
  2. void onError(
    1. String error
    )?,
  3. void onProgress(
    1. double progress
    )?,
  4. String? downloadFileName,
})
override

Implementation

@override
Future<void> downloadAndInstallApk({
  required String downloadFileUrl,
  void Function(String error)? onError,
  void Function(double progress)? onProgress,
  String? downloadFileName,
}) async {
  try {
    if (downloadFileUrl.trim().isEmpty) {
      onError?.call("Download File Url is empty");
      return;
    }

    await ApiService().downloadFile(
      downloadFileUrl: downloadFileUrl,
      downloadFileName: downloadFileName,
      onSuccess: (filePath) async {
        await _channel.invokeMethod<String>('downloadAndInstallApk', {
          "path": filePath,
        });
      },
      onError: (error) {
        onError?.call(error);
      },
      onProgress: (progress) {
        onProgress?.call(progress);
      },
    );
  } on PlatformException catch (e, sc) {
    printLog(e.toString(), stackTrace: sc);
    if (onError != null) {
      onError(e.message ?? "");
    }
  } catch (e, sc) {
    printLog(e.toString(), stackTrace: sc);
    onError?.call(e.toString());
  }
}