Viewing version 4.0.0. Open the latest package page.
cached_network_image_ce
4.0.0Community Edition Flutter library to load and cache network images. Can also be used with placeholder and error widgets.
Readme
Cached Network Image — Community Edition
A Flutter library to show images from the internet and keep them in the cache directory. Community maintained fork of cached_network_image.
Why this fork?
The original cached_network_image by Baseflow has been unmaintained for over 2 years, with no updates, bug fixes, or responses to issues and pull requests. This community edition was created to:
- Keep the package alive — continue fixing bugs and adding features the community needs.
- Replace
sqflitewithhive_cefor cache storage — the original package depended onflutter_cache_manager(also by Baseflow) which usedsqfliteunder the hood. This community edition useshive_ceinstead, which is more performant and actively maintained. - Stay up-to-date with the latest Flutter and Dart SDK versions.
How to use
The CachedNetworkImage can be used directly or through the ImageProvider.
Both CachedNetworkImage and CachedNetworkImageProvider have minimal support for web (currently without caching).
With a placeholder:
CachedNetworkImage(
imageUrl: 'https://via.placeholder.com/350x150',
placeholder: (context, url) => CircularProgressIndicator(),
errorWidget: (context, url, error) => Icon(Icons.error),
),
Or with a progress indicator:
CachedNetworkImage(
imageUrl: 'https://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 image provider to use in another widget you can provide an imageBuilder:
CachedNetworkImage(
imageUrl: 'https://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 crash you are fine to report an issue, but do that with a small example so we can reproduce that crash.
Contributing
Contributions are welcome! Please see the contributing guide for details.
License
This project is licensed under the MIT License.
Changelog
[3.4.1] - 2024-08-13
- Target js_interop for Wasm support
[3.4.0] - 2024-04-10
- Change how errors are reported by ImageLoader. Emitting errors as streams instead of re-throwing.
- Improved debug console messages
- Update dependencies
- added static field defaultCacheManager to CachedNetworkImageProvider
- Expose scale of CachedNetworkImageProvider on CachedNetworkImage
[3.3.1] - 2023-12-31
- Adding an errorListener prevents automatic reporting to global error handler.
[3.3.0] - 2023-09-25
- Add error to ErrorListener
- Update to Dart 3
- Remove
load, useloadImageinsteadloadBuffer
Minor code clean-ups:
- Add topics in pubspec
- Specify types
- Update example
[3.2.3] - 2022-11-25
- Correctly dispose image stream handler
[3.2.2] - 2022-08-31
- loadBuffer is added and used instead of load
[3.2.1] - 2022-05-16
- Update to Flutter 3
[3.2.0] - 2021-11-29
- Add option to set the log level of the cache manager, for example:
CachedNetworkImage.logLevel = CacheManagerLogLevel.debug;
- Update cache manager dependency.
[3.1.0+1] - 2021-11-04
- Update Readme
[3.1.0] - 2021-07-16
- Separate Web and IO implementations
[3.0.0] - 2021-03-27
- Migrate to null safety
- Fix "Cannot clone a disposed image" error
- Update dependencies.
[3.0.0-nullsafety] - 2021-01-02
- Migrate to null safety
[2.5.1] - 2021-03-09
- Update dependencies
[2.5.0] - 2020-12-22
- Add support for resizing images in disk cache.
CachedNetworkImage(
maxHeightDiskCache: 200,
imageUrl: 'https://via.placeholder.com/3000x2000',
);
[2.4.1] - 2020-12-01
- Fix a bug that an image is disposed when it shouldn't.
[2.4.0] - 2020-11-30
- Added support for a cache key which is different from the image url.
[2.3.3] - 2020-10-16
- Support for flutter_cache_manager 2.x.x.
[2.3.2] - 2020-09-10
- Fixed placeholders and error widgets, those are not always centered anymore.
- Evict an image from ImageCache if image fails to load.
- Added method to evict an image from memory and disk cache.
[2.3.1] - 2020-08-25
- Fixed fading when the image has no placeholder or progress indicator.
[2.3.0] - 2020-08-25
- Improved image loading by using OctoImage. OctoImage uses the native callbacks of the ImageProvider instead of loading the file when the ImageWidget is build the first time.
- Set minimal Flutter version to 1.20.0; first compatible stable version.
- Added choice for rendering of images on web. Defaults to standard HTML ImageElement, but gives the option to use a custom HTTP Get for headers and skia support.
- Use a MultiImageStreamCompleter for when an image that is available in the cache is updated.
[2.3.0-rc] - 2020-06-20
- Added choice for rendering of images on web. Defaults to standard HTML ImageElement, but gives the option to use a custom HTTP Get for headers and skia support.
- Use a MultiImageStreamCompleter for when an image that is available in the cache is updated.
- Increase minimal version of Flutter to 1.19.0-2.0.pre (currently requires Beta) due to an error listener bug.
[2.3.0-beta.1] - 2020-05-28
- Improved web support: support for headers and skia.
[2.3.0-beta] - 2020-05-20
- Rewrote image widget by using OctoImage.
[2.2.0+1] - 2020-05-05
- Fix ImageProvider not using provided headers.
[2.2.0] - 2020-04-30
- Upgrades on CachedNetworkImageProvider:
- Support for download progress.
- Basic web support (no caching).
[2.1.0+1] - 2020-04-10
- Update minimal Dart sdk version
[2.1.0] - 2020-04-10
- Update CacheManager
- Added option for progress indicator
[2.0.0] - 2019-12-31
- Public release of 2.0 version
[2.0.0-rc.1] - 2019-11-04
- Revert scaling of image due to issues with BoxFit.
[2.0.0-rc] - 2019-10-17
- BREAKING CHANGE: Compatibility for breaking change in Flutter 1.10.15
[1.1.3] - 2019-11-04
- Revert scaling of image due to issues with BoxFit.
[1.1.2+1] - 2019-10-17
- Fix for widgets declared with infinite size.
[1.1.2] - 2019-10-16
- Add filterQuality property.
- Scale image to size when showing in widget.
- Better error handling.
- Fix for useOldImageOnUrlChange.
- Update cache manager to 1.1.2.
[1.1.1] - 2019-07-23
- Updated cache manager for error handling fix
[1.1.0] - 2019-07-13
- Improved performance
- Keep fetched files in sync with filemanager.
- Better error handling.
- Added extra example to show the imageBuilder
[1.0.0] - 2019-06-27
- Updated dependencies
[0.8.0] - 2019-05-06
- Fixed compile error on informationCollector by temporarily disabling it.
[0.7.0] - 2019-03-06
- BREAKING CHANGE: Renamed ErrorWidgetBuilder to LoadingErrorWidgetBuilder
- LoadingErrorWidgetBuilder returns an Object instead of an Exception
- Fixed BoxFit to also work when size is not defined
[0.6.2] - 2019-02-27
- Added option to blend image with color
- Added option in CacheManager to clear the cache
[0.6.1] - 2019-02-25 BREAKING CHANGES
- No longer assume infinite size.
[0.6.0] - 2019-02-18 BREAKING CHANGES
- Breaking changes in API and behaviour
- Very much improved though
- Adapted for new cache manager library
- Completely rewritten image view
- Now using builders for placeholder and error widgets
- Added optional builder to customize the image
[0.5.1] - 2018-11-19
- Fixed error throwing
[0.5.0] - 2018-10-13
- Updated cache manager for http 0.12.0
[0.4.2] - 2018-08-30
- Updated cache manager dependency
[0.4.1] - 2018-04-27
- Improved error handling when a file could not be loaded.
[0.4.0] - 2018-04-14
- Added optional headers.
- Changed to Dart 2.0
- Fixed bug when updating widget with new url
[0.3.0] - 2018-02-09
- Added CachedNetworkImage with placeholder and error widgets.
[0.2.1] - 2018-01-08
- Moved from OneFrameImageStreamCompleter to MultiFrameImageStreamCompleter.
- Updated CacheManager dependency for critical bug fix.
[0.2.0] - 2017-12-29
- Breaking change Removed CachedNetworkImage. From now on only the ImageProvider is supported. For a placeholder use
FadeInImage. See also "Fallback for Network Images". - Moved CacheManager to a separate library for a more generic purpose.
[0.1.0] - 2017-12-21
- Breaking change. Upgraded to Gradle 4.1 and Android Studio Gradle plugin 3.0.1. Older Flutter projects need to upgrade their Gradle setup as well in order to use this version. Instructions can be found here.
[0.0.2] - 10 December 2017
Added an ImageProvider and improved documentation
[0.0.1] - 2 December 2017
Initial release, should be polished
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'cached_network_image_ce:4.0.0'pubspec.yaml
name: cached_network_image_ce
description: Community Edition Flutter library to load and cache network images.
Can also be used with placeholder and error widgets.
homepage: https://github.com/Erengun/flutter_cached_network_image_ce
topics:
- cache
- image
- network-image
version: 4.0.0
environment:
sdk: ^3.0.0
flutter: '>=3.10.0'
dependencies:
cached_network_image_platform_interface_ce: ^5.0.0
cached_network_image_web_ce: ^2.0.0
file: '>=7.0.0 <8.0.0'
flutter:
sdk: flutter
hive_ce: ^2.0.0
http: ^1.6.0
octo_image: ^2.1.0
path: ^1.8.0
path_provider: ^2.0.0
dev_dependencies:
flutter_lints: ^4.0.0
flutter_test:
sdk: flutter
mocktail: ^1.0.4
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 4.0.0 | Cached · Upstream SHA-256 matched | Download | 5b102eeb…5d62ee |
| 4.0.1 | Cached · Upstream SHA-256 matched | Download | bede5b1e…8351a8 |
| 4.1.0 | Cached · Upstream SHA-256 matched | Download | 78e06dad…c2d970 |
| 4.1.1 | Cached · Upstream SHA-256 matched | Download | 167b590c…614da9 |
| 4.2.0 | Cached · Upstream SHA-256 matched | Download | 9a868c4a…70c5d6 |
| 4.3.0 | Cached · Upstream SHA-256 matched | Download | 9892eb90…60df4c |
| 4.4.0 | Cached · Upstream SHA-256 matched | Download | f2d9ac38…3a0a93 |
| 4.5.0 | Cached · Upstream SHA-256 matched | Download | 57e6434e…b4fc1c |
| 4.6.0 | Cached · Upstream SHA-256 matched | Download | 7708ac41…8845ba |
| 4.6.1 | Cached · Upstream SHA-256 matched | Download | 4084b07d…befcb4 |
| 4.6.2 | Cached · Upstream SHA-256 matched | Download | c95695c9…b55301 |
| 4.6.3 | Cached · Upstream SHA-256 matched | Download | ee8e3631…0da1ae |
| 4.6.4 | Cached · Upstream SHA-256 matched | Download | d4701fbb…ad5fff |
| 4.7.0 | Cached · Upstream SHA-256 matched | Download | da6edbc8…77bded |
| 4.8.0 | Cached · Upstream SHA-256 matched | Download | f755f124…375181 |
| 4.9.0 | Cached · Upstream SHA-256 matched | Download | 9c61372f…ae6840 |
| 4.9.1 | Cached · Upstream SHA-256 matched | Download | 2d76205e…d9861b |
| 4.10.0 | Cached · Upstream SHA-256 matched | Download | 974594da…3e6e98 |
| 4.10.1 | Cached · Upstream SHA-256 matched | Download | 20d35070…928084 |
| 4.11.0 | Cached · Upstream SHA-256 matched | Download | bdbc622b…7fbddd |
| 4.11.1 | Cached · Upstream SHA-256 matched | Download | 8fdd544f…e542a8 |
| 4.12.0 | Cached · Upstream SHA-256 matched | Download | 9165bb98…8200ba |
| 4.13.0 | Cached · Upstream SHA-256 matched | Download | 13912195…c2c17e |
| 4.13.1 | Cached · Upstream SHA-256 matched | Download | 8bc77b76…c014b2 |
Dependencies
cached_network_image_platform_interface_ce "^5.0.0"
cached_network_image_web_ce "^2.0.0"
file "\u003e=7.0.0 \u003c8.0.0"
flutter {
"sdk": "flutter"
}
hive_ce "^2.0.0"
http "^1.6.0"
octo_image "^2.1.0"
path "^1.8.0"
path_provider "^2.0.0"