flutter_cached_network_image icon indicating copy to clipboard operation
flutter_cached_network_image copied to clipboard

Don’t show placeholder when loaded from cache

Open msw333 opened this issue 6 years ago • 19 comments

Maybe I am doing something wrong: it is perfect to show a placeholder, like a progress indicator, when an image is loaded from a web source.

But I don’t think it is a good idea to show a placeholder when images are loaded from cache, since they can appear directly.

Highly appreciate your comment on that.

msw333 avatar Apr 16 '19 16:04 msw333

I agree.

If the image has already been downloaded once, even after restarting the application, it should be displayed immediately instead of the placeholder.

It is the last thing I need. It would be great!

crush3r avatar Apr 23 '19 08:04 crush3r

I agree this needs fixing, it looks terrible in list based apps when a placeholder flashes up for a split second while the cached image is loaded. Placeholder should only be shown when getting an image across the network or if no image exists.

roidy avatar May 15 '19 08:05 roidy

Maybe a simple new parameter allowing us to choose if we want or not this behavior

cubissimo avatar Jun 03 '19 20:06 cubissimo

Would you want to keep the fading animation in that case or not?

renefloor avatar Jul 15 '19 06:07 renefloor

@renefloor I think if the image already exists in cache, it should display immediately just like a regular image, without any fading animation.

hgl avatar Jul 19 '19 03:07 hgl

Hi, I have the same problem here, I am using this in the listview, and when I scroll up or down, although the images are cached, but there's still a split second before the image is shown.

KaiP-598 avatar Aug 16 '19 02:08 KaiP-598

its very important to me to avoid placeholder on cached images. so is any of you found a solution for this?

ejdrian313 avatar Feb 09 '20 19:02 ejdrian313

Any updates on this? Kind of a deal breaker for me..

kansson avatar Feb 13 '20 23:02 kansson

Joining this issue, a way to avoid that split second flash for an already cached image would be a great touch.

royibernthal avatar Apr 20 '20 14:04 royibernthal

Hello. Any update on this? It is a deal breaker for me too.

SvehlaJan avatar Oct 04 '20 09:10 SvehlaJan

little workaround I created this widget to use with CachedNetworkImageProvider:

class ImageWidgetPlaceholder extends StatelessWidget {
  const ImageWidgetPlaceholder({Key key, this.image, this.placeholder})
      : super(key: key);

  final ImageProvider image;
  final Widget placeholder;

  @override
  Widget build(BuildContext context) {
    return Image(
      image: image,
      frameBuilder: (BuildContext context, Widget child, int frame,
          bool wasSynchronouslyLoaded) {
        if (wasSynchronouslyLoaded) {
          return child;
        } else {
          return AnimatedSwitcher(
            duration: Duration.zero,
            child: frame != null ? child : placeholder,
          );
        }
      },
    );
  }
}

with use in a container:

Container(
      decoration: BoxDecoration(
        image: DecorationImage(
          image: CachedNetworkImageProvider(
            page['image'],
          ),
          fit: BoxFit.fill,
        ),
      ),

or if you now size of the image avoid layout jump:

ImageWidgetPlaceholder(
                          image: CachedNetworkImageProvider(
                            multiselect['imageUrl'],
                          ),
                          placeholder: SizedBox(
                            width: MediaQuery.of(context).size.width,
                            height: 200,
                          ),
                        )

ejdrian313 avatar Oct 05 '20 06:10 ejdrian313

Amazing library, starred!

but unfortunately, this is a dealbreaker for me too

grantespo avatar Oct 11 '20 03:10 grantespo

Any updates on this? This is a dealbreaker for me as well.

@ejdrian313 unfortunately your solution does not work (I've tested it), because regardless of loading from the network, the database, or the memory, CacheStore returns a future.

cemozerr avatar Dec 26 '20 21:12 cemozerr

I dug deep into this issue and, correct me if I'm wrong @renefloor but, it seems like even if the image information is held in memory, the FlutterCacheManager holds the image bytes on disk. This seems to be why the image can't be displayed instantaneously.

Or generally, rather that the cache implementation the CachedNetworkImage uses does not have synchronous return methods for the image bytes that are stored either on disk or memory.

I'm currently trying to create a solution where I use a Map with limited size that return Image's Uint8List bytes as my in-memory cache, and if that cache does not contain the key I'm looking for, I'll use the CachedNetworkImageProvider to retrieve and cache the image on disk. After that caching on disk, I'm planning to save the image bytes in my in-memory cache.

UPDATE: that didn't work either. Even with image bytes or the image object itself in memory, returned with a synchronous call, the image still "flickers" before rendering properly. Here's the gist if anyone wants to see: https://gist.github.com/cemozerr/a6464251385fa7d55b7068b773d2d2b3

cemozerr avatar Dec 27 '20 21:12 cemozerr

Anyone has an update on this? Got the same issue, don't want to see the progress indicator when loaded from cache

royvangeel avatar Dec 29 '21 14:12 royvangeel

Any updates on this?

zaidalsaied avatar Jun 12 '22 08:06 zaidalsaied