Al-Hashimy
Al-Hashimy

Reputation: 469

Caching images on mobile with flutter

I used https://pub.dev/packages/cached_network_image to cache images it's work with pages but when I re open the app again it reload the image again, I need to store the image on mobile with database and call it again or something like that

Upvotes: 0

Views: 563

Answers (1)

if when you enter again it reloads the image it is because something failed with the cache, try with this code use these plugins

cached_network_image: ^3.0.0 flutter_cache_manager: ^3.2.0

static final customCacheManager = CacheManager(Config('customCacheKey',
      stalePeriod: Duration(days: 15), maxNrOfCacheObjects: 100));
              CachedNetworkImage(
                cacheManager: customCacheManager,
                height: 40,
                width: 40,
                fit: BoxFit.cover,
                imageUrl: imageUrl,
                placeholder: (context, url) => CircularProgressIndicator(
                  valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
                  backgroundColor: const Color(0xFF02204c),
                ),
                errorWidget: (context, url, error) => Center(
                  child: Image.asset(
                    'assets/images/errorImage.png',
                    height: 60,
                    width: 60,
                  ),
                ),
              ),

Upvotes: 1

Related Questions