downloadAndEnable method

Future<void> downloadAndEnable({
  1. required ZipDownloadProgressCallback onProgress,
})

Implementation

Future<void> downloadAndEnable({
  required ZipDownloadProgressCallback onProgress,
}) async {
  if (isEnabled()) return;

  if (kIsWeb) {
    markEnabled();
    onProgress(100.0);
    return;
  }

  final baseDir = await getApplicationDocumentsDirectory();
  final destDir = Directory('${baseDir.path}/$dirName');
  final zipFile = File('${baseDir.path}/$zipName');

  _indexReady = false;
  _filePathBySurah.clear();

  await ZipDownloadService.downloadAndExtract(
    urls: zipUrls,
    zipFile: zipFile,
    destinationDir: destDir,
    onProgress: onProgress,
    logName: logName ?? 'SuraJsonDownload:$dirName',
    minZipSizeBytes: minZipSizeBytes,
  );

  await _ensureIndex();
  if (_filePathBySurah.isEmpty) {
    throw Exception('تم التحميل لكن لم يتم العثور على ملفات sura_###.json');
  }

  markEnabled();
}