loadPersistedFontsBulk method
يقوم بتحميل وتسجيل جميع الصفحات المحفوظة دفعة واحدة (Bulk)
- يقرأ القائمة من GetStorage.loadedFontPages
- يتخطّى الصفحات المسجّلة في الذاكرة state.loadedFontPages
- يعمل على دفعات صغيرة لتجنّب حجب واجهة المستخدم
Implementation
Future<void> loadPersistedFontsBulk({
List<int>? pages,
int batchSize = 24,
}) async {
try {
final storage = GetStorage();
final stored = (pages ??
(storage
.read<List<dynamic>>(_StorageConstants().loadedFontPages)
?.cast<int>() ??
[]))
.where((p) => p >= 0 && p < 604)
.toSet()
.toList()
..sort();
if (stored.isEmpty) return;
// تحميل على دفعات صغيرة لتجنّب الجانك
for (int i = 0; i < stored.length; i += batchSize) {
final chunk =
stored.sublist(i, (i + batchSize).clamp(0, stored.length));
for (final page in chunk) {
// سيقوم loadFont بتخطّي الصفحة إذا كانت محمّلة مسبقًا
await loadFont(page, isFontsLocal: true);
}
// بعد كل دفعة على المنصات غير الويب: أعد بناء الواجهة كي تنعكس الخطوط
// On non-web, a chunk-level rebuild is sufficient; web already rebuilds per page load
if (!kIsWeb && !isClosed) {
try {
update();
} catch (_) {}
}
// فسح المجال للإطار التالي
await Future.delayed(const Duration(milliseconds: 1));
}
} catch (e) {
log('Bulk load persisted fonts failed: $e', name: 'FontsLoad');
}
}