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.
Contribute to this on GitHub
Download, cache and show images in a flutter app https://github.com/Baseflow/flutter_cached_network_image 740 forks. 2,590 stars. 329 open issues. Recent commits: fix: Avoid decoding static images again when a listener is re-added (#1062)* fix: Avoid decoding static images again when a listener is re-added* test: Add tests for image stream completer behavior with listeners and its states* fix: Prevent redundant decoding of static images during listener re-addition* chore: Bump version to 4.0.6* docs(changelog): Document 4.0.6 for static image re-decode fix* fix: Simplify disposal logic for static images during decoding* docs(changelog): Replace version 4.0.6 to 4.0.5 and clarify static image decoding issues* fix: Reset emitted frame count when a new codec is ready* refactor: Replace _currentCodecHasImage with _framesEmitted* fix: Resume waiting animated frame when a listener is re-added* fix: Drop waiting animated frame when the codec changes* test: Add tests for animated re-listen, codec changes and failed decodes* chore: Set version to 4.0.5* docs(changelog): Document animated re-listen and codec reset fixes* fix: Guard app frame callback against a dropped waiting frame , GitHub Bump dependencies in cached_network_image (#1059)* Bump dependencies in cached_network_imageRaise flutter_cache_manager to ^3.4.5, material_ui to ^1.3.0, octo_imageto ^2.1.1 and mocktail to ^1.0.5. material_ui 1.3.0 is the newestrelease that keeps the Dart ^3.12 / Flutter >=3.44 floor.Bring the example along: flutter_lints ^6.0.0, flutter_blurhash ^0.9.1,baseflow_plugin_template ^2.2.1, and an SDK constraint that matches thepackage it depends on.Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>* Reformat the example for the tall styleRaising the example's SDK constraint to ^3.12.0 selects the tall styleformatter, which failed the Format check on example/lib/main.dart.Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>———Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> , GitHub Bump dependencies in cached_network_image_platform_interface (#1057)Raise flutter_cache_manager to ^3.4.5 and material_ui to ^1.3.0, thenewest material_ui that keeps the Dart ^3.12 / Flutter >=3.44 floor.Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> , GitHub Bump dependencies in cached_network_image_web (#1058)Raise flutter_cache_manager to ^3.4.5, material_ui to ^1.3.0 and web to^1.1.1. material_ui 1.3.0 is the newest release that keeps the Dart^3.12 / Flutter >=3.44 floor.Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> , GitHub Adds `debugLabel` for the image stream completer (#984)* Update multi_image_stream_completer.dart* Update cached_network_image_provider.dart* Update multi_image_stream_completer.dart* Add debugLabel tests and bump cached_network_image to 4.0.3* Update cached_network_image/test/image_provider_test.dartCo-authored-by: Rick van Dijk <rickavdijk@gmail.com>———Co-authored-by: Rick van Dijk <rickavdijk@gmail.com> , GitHub
Provides the list of the opensource Flutter apps collection with GitHub repository.