cached network image
a flutter library to show images from the internet and keep them in the cache directory.
how to use
the cachednetworkimage can be used directly or through the imageprovider.
both the cachednetworkimage as cachednetworkimageprovider have minimal support for web. it currently doesn’t include caching.
with a placeholder:
cachednetworkimage(
imageurl: "http://via.placeholder.com/350x150",
placeholder: (context, url) => circularprogressindicator(),
errorwidget: (context, url, error) => icon(icons.error),
),
or with a progress indicator:
cachednetworkimage(
imageurl: "http://via.placeholder.com/350x150",
progressindicatorbuilder: (context, url, downloadprogress) =>
circularprogressindicator(value: downloadprogress.progress),
errorwidget: (context, url, error) => icon(icons.error),
),
image(image: cachednetworkimageprovider(url))
when you want to have both the placeholder functionality and want to get the imageprovider to use in another widget you can provide an imagebuilder:
cachednetworkimage(
imageurl: "http://via.placeholder.com/200x150",
imagebuilder: (context, imageprovider) => container(
decoration: boxdecoration(
image: decorationimage(
image: imageprovider,
fit: boxfit.cover,
colorfilter:
colorfilter.mode(colors.red, blendmode.colorburn)),
),
),
placeholder: (context, url) => circularprogressindicator(),
errorwidget: (context, url, error) => icon(icons.error),
),
how it works
the cached network images stores and retrieves files using the flutter_cache_manager.
faq
my app crashes when the image loading failed. (i know, this is not really a question.)
does it really crash though? the debugger might pause, as the dart vm doesn’t recognize it as a caught exception; the console might print errors; even your crash reporting tool might report it (i know, that really sucks). however, does it really crash? probably everything is just running fine. if you really get an app crashes you are fine to report an issue, but do that with a small example so we can reproduce that crash.
see for example this or this answer on previous posted issues.
Comments are closed.