ensurePagesLoaded static method
تحميل الصفحات القريبة من centerPage (1-based) بنصف قطر radius.
مثال: ensurePagesLoaded(100, radius: 10) يحمّل الصفحات 90–110.
يتم تخطّي الصفحات المحمّلة مسبقًا. يُنتظر حتى انتهاء التحميل.
Implementation
static Future<void> ensurePagesLoaded(
int centerPage, {
int radius = 10,
}) async {
final cacheDir = await _ensureCacheDir();
final start = (centerPage - radius).clamp(1, _totalPages);
final end = (centerPage + radius).clamp(1, _totalPages);
final futures = <Future<void>>[];
for (int p = start; p <= end; p++) {
if (!_loadedPages.contains(p)) {
futures.add(_loadSinglePage(p, cacheDir));
}
}
if (futures.isNotEmpty) {
await Future.wait(futures);
}
}