Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application crashes when using CachedNetworkImage

Tags:

flutter

dart

Application crashes when using CachedNetworkImage in listview. If there are a lot of pictures, then the application freezes and crashes. Is it possible to load each image one by one, asynchronously? Can I have a code example? Thanks.

like image 790
Samoilov Avatar asked May 17 '26 12:05

Samoilov


1 Answers

And so, if you have the same problem as me, and you have a large list of pictures, then you can do the following:

1.Enable ListView pagination. So that when scrolling, not the entire ListView is loaded, but for example only 10 items from the List.

2.Compress pictures to the desired size using the following parameters: memCacheWidth, memCacheHeight, maxHeightDiskCache, maxWidthDiskCache

Here is my example:

CachedNetworkImage(
    memCacheWidth: 45,
    memCacheHeight: 60,
    maxHeightDiskCache: 60,
    maxWidthDiskCache: 45,
    imageUrl: imageUrl,
    imageBuilder: (context, imageProvider) => imageBuilderWidget(imageProvider),
    placeholder: (context, url) => placeholderWidget(),
    errorWidget: (context, url, error) => errorWidget(),
  );

After adding these options, remove app from the emulator and do a flutter clean

like image 55
Samoilov Avatar answered May 20 '26 03:05

Samoilov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!