deleteFonts method

Future<void> deleteFonts()

Deletes the font at the specified index.

This method asynchronously deletes the font from the storage or database based on the provided fontIndex.

fontIndex: The index of the font to be deleted.

Returns a Future that completes when the font has been deleted.

Implementation

Future<void> deleteFonts() async {
  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(_StorageConstants().isDownloadedCodeV2Fonts, false);
      GetStorage().write(_StorageConstants().fontsSelected, 0);
      // state.fontsDownloadedList.elementAt(fontIndex);
      GetStorage().write(
          _StorageConstants().fontsDownloadedList, state.fontsDownloadedList);
      state.isDownloadedV2Fonts.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');
  }
}