perf: optimize home screen rendering with ListView.builder and improve image loading performance by persisting disk cache

This commit is contained in:
pradeepkumar
2026-04-10 20:18:21 +05:30
parent cdb918fae8
commit 1abcc2416f
3 changed files with 25 additions and 32 deletions

View File

@@ -1,7 +1,5 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:real_estate_mobile/config/app_config.dart';
import 'package:real_estate_mobile/config/firebase_config.dart';
@@ -15,13 +13,12 @@ Future<void> mainCommon(Flavor flavor) async {
await Firebase.initializeApp(options: FirebaseConfig.currentOptions);
// Clear stale image caches on app start to ensure fresh presigned URLs
// Only clear the in-memory presigned URL cache — NOT the disk image cache.
// Presigned URLs expire after ~1 hour and are re-fetched lazily by
// ImageUrlResolver when needed. The disk cache (CachedNetworkImage) must
// persist across restarts for app smoothness — clearing it on every start
// forces every image to re-download, causing visible delay on all screens.
ImageUrlResolver.instance.clearCache();
PaintingBinding.instance.imageCache.clear();
PaintingBinding.instance.imageCache.clearLiveImages();
// Also clear CachedNetworkImage disk cache so old presigned URLs
// (which may point to stale/wrong images) don't persist across sessions.
DefaultCacheManager().emptyCache();
runApp(const ProviderScope(child: MyApp()));
}