image_cache 1.0.0 copy "image_cache: ^1.0.0" to clipboard
image_cache: ^1.0.0 copied to clipboard

A flutter package which shows an image. Gets it from an URL and then saves it in your local storage.

This package provides a widget to show images from an url and them get it from your local storage. It uses image_cache package

Features #

FileCache downloads the image and saves it into your local path. The next time the app read the same image, it will return the local path.

The Pro is that you manage the downloaded files, you decide when to clear this cache instead of the cache managed by the device.

Getting started #

It's very simple to use, you only have to define the cache folder name where you want to save the downloaded files.

Usage #

You have to create the cache file and the local path (optional) where you want to download the files:

/* create cache */
var fileCache = FileCache();

You can use fileCache to get the file path from an url. The first time, the cache will get the file from the url, download it & save it. The next time you call this method with the same url, the cache will return the local uri of the file.

/* Example: get an image from cache */
Image getImageLocalPath( ) async {
 
  // get file path from cache
  String imagePath = await fileCache.getFilePath(url);

  /* and then you can create an image from the imagePath (local uri) */
  Image image = Image.file(File(imagePath));
  image.image.resolve(ImageConfiguration()).addListener(
    ImageStreamListener((ImageInfo image, bool synchronousCall) {
      var myImage = image.image;
      Size size = Size(myImage.width.toDouble(), myImage.height.toDouble());
      completer.complete(ImageCacheInfo(size, imagePath));
    },
    ),
  );
  return image;
}

How it works #

The widget stores and retrieves files using the file_cache_provider.

Additional information #

2
likes
150
points
28
downloads

Publisher

unverified uploader

Weekly Downloads

A flutter package which shows an image. Gets it from an URL and then saves it in your local storage.

Repository (GitHub)
View/report issues

Topics

#cache #file #image

Documentation

API reference

License

MIT (license)

Dependencies

file_cache_provider, flutter, loading_animation_widget

More

Packages that depend on image_cache