deleteOldFonts method

Future<void> deleteOldFonts()

Implementation

Future<void> deleteOldFonts() async {
  if (GetStorage().read('isDownloadedCodeV2Fonts') == true) {
    try {
      state.fontsDownloadedList.value = [];
      final fontsDir = Directory('${_dir.path}/quran_fonts');

      // التحقق من وجود مجلد الخطوط
      if (await fontsDir.exists()) {
        // حذف جميع الملفات والمجلدات داخل مجلد الخطوط
        await fontsDir.delete(recursive: true);
        log('Fonts directory deleted successfully.');

        // تحديث حالة التخزين المحلي
        GetStorage().write('isDownloadedCodeV2Fonts', false);
        GetStorage().write(_StorageConstants().fontsSelected, 0);
        // state.fontsDownloadedList.elementAt(fontIndex);
        GetStorage().write(_StorageConstants().fontsDownloadedList,
            state.fontsDownloadedList);
        state.isFontDownloaded.value = false;
        state.fontsSelected.value = 0;
        state.fontsDownloadProgress.value = 0;
        Get.forceAppUpdate();
      } else {
        log('Fonts directory does not exist.');
      }
    } catch (e) {
      log('Failed to delete fonts: $e');
    }
  }
}