flutter_cached_network_image icon indicating copy to clipboard operation
flutter_cached_network_image copied to clipboard

Images inside listview reloads when top page pops

Open harshapulikollu opened this issue 4 years ago • 12 comments

🔙 Regression

Images inside a listview of screen-1 reload(displaying placeholder and showing image) when screen-2 pops from the navigation stack.

Screen 1 is the main page that shows when the app opens. The user navigates to screen 2 by clicking on a button and comes back to screen 1 by clicking the back button. At that time the images show blurhash and then show the actual image.

PS: I'm using this package along with OctoImage package.

Old (and correct) behavior

Image Should be displayed as it's already loaded.

Current behavior

Image shows placeholder and reloads image like it did on the first load.

Reproduction steps

Using a CachedNetworkImage widget on screen 1 and open screen2 and remove screen2 from the view.

OctoImage(
             image: CachedNetworkImageProvider(Url),
             placeholderBuilder: OctoPlaceholder.blurHash(
                   'LJH1#:Nz#MMgxdIV-nRrIaxVr_XA',
             ),
             errorBuilder: OctoError.blurHash('LJH1#:Nz#MMgxdIV-nRrIaxVr_XA',
                 icon: Icons.warning_amber_rounded),
             fit: BoxFit.cover,
             height: double.infinity,
             width: double.infinity,
           );

Configuration

Version: 2.5.0

Platform:

  • [X] :iphone: iOS
  • [X] :robot: Android

harshapulikollu avatar Dec 25 '20 10:12 harshapulikollu

I have same problem

refcoding avatar Jan 14 '21 07:01 refcoding

+1

I'm having this problem with ListViews inside ListViews. Not all the images reload with the placeholder appearing first, but it seems to happen randomly. Also it seems to happen more frequently if there are more images in the ListViews.

snaeji avatar Jan 19 '21 14:01 snaeji

I have found the cause of the problem. My picture file is too large. flutter.dev @harshapulikollu @snaeji

refcoding avatar Feb 27 '21 10:02 refcoding

I have found the cause of the problem. My picture file is too large. flutter.dev @harshapulikollu @snaeji

Thank you for letting us know @refcoding, I'll try to compress the size of the image and test it.

harshapulikollu avatar Feb 28 '21 06:02 harshapulikollu

image 是这里的问题,flutter缓存框架imageCache最大100M,1000张图片,超出就remove,设置更改一下最大值

Wellcomezhangheng avatar Mar 03 '21 12:03 Wellcomezhangheng

I have bumped the maximumSizeBytes const _kDefaultSizeBytes value from 100 << 20 to 1000 << 20 in ImageCache file, and images are not reloading any more. But I donno how effective that solution is and I think, I have to manually update it every time I update the flutter version.

harshapulikollu avatar Mar 03 '21 17:03 harshapulikollu

我将文件中的maximumSizeBytes常_kDefaultSizeBytes量值从100 << 20 更改1000 << 20ImageCache,并且图像不再重新加载。但是我不知道该解决方案的有效性,我认为,每次更新Flutter版本时,我都必须手动对其进行更新。

PaintingBinding.instance.imageCache.maximumSizeBytes = 1000<<20; //1000M

Wellcomezhangheng avatar Mar 04 '21 02:03 Wellcomezhangheng

我将文件中的maximumSizeBytes常_kDefaultSizeBytes量值从100 << 20 更改1000 << 20ImageCache,并且图像不再重新加载。但是我不知道该解决方案的有效性,我认为,每次更新Flutter版本时,我都必须手动对其进行更新。

PaintingBinding.instance.imageCache.maximumSizeBytes = 1000<<20; //1000M

thanks,It works

jsonsuxing avatar Apr 22 '21 07:04 jsonsuxing

我将文件中的maximumSizeBytes常_kDefaultSizeBytes量值从100 << 20 更改1000 << 20ImageCache,并且图像不再重新加载。但是我不知道该解决方案的有效性,我认为,每次更新Flutter版本时,我都必须手动对其进行更新。

PaintingBinding.instance.imageCache.maximumSizeBytes = 1000<<20; //1000M

thanks,It works

In which file are you making the change?

Alusio avatar May 09 '21 09:05 Alusio

@Alusio You can make the change on any page. I did it on my home_page.dart file

Rohithgilla12 avatar Sep 08 '21 05:09 Rohithgilla12

The solution here on StackOverflow worked for me!

https://stackoverflow.com/q/54377133/4254290

class CustomImageCache extends WidgetsFlutterBinding {
  @override
  ImageCache createImageCache() {
    ImageCache imageCache = super.createImageCache();
    // Set your image cache size
    imageCache.maximumSizeBytes = 1024 * 1024 * 100; // 100 MB, make this bigger if needed
    return imageCache;
  }
}

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  if (kReleaseMode) {
     CustomImageCache();
  }
  runApp(MyApp());
}

snaeji avatar Sep 13 '21 15:09 snaeji

Hi,

I print PaintingBinding.instance.imageCache.maximumSizeBytes // 100MB Here, I go to settings -> iphone memory and see Documents and Data cache> 100MB. This is why the image is reloaded. Solution: I would set PaintingBinding.instance.imageCache.maximumSizeBytes 1000<< 20; //1000MB Problem solved

thongvo109 avatar Jun 21 '23 13:06 thongvo109