disposable_cached_images 0.0.1 copy "disposable_cached_images: ^0.0.1" to clipboard
disposable_cached_images: ^0.0.1 copied to clipboard

outdated

Flutter package for displaying images from the Internet and keeping them in the cache directory.

Flutter package for displaying images from the Internet and keeping them in the cache directory with disposal feature to reduce bandwidth and memory usage.

Features #

Download images from the Internet and keep them in the cache directory.

Cancel the download if the image widget has been disposed to reduce bandwidth usage.

Remove the image from memory if the image widget has been disposed to reduce device memory usage.

Usage #

Setting up #

Add scaffoldMessengerKey to the MaterialApp

you can read more about scaffoldMessengerKey on docs.flutter

    MaterialApp(
    home: const Home(),
    scaffoldMessengerKey: scaffoldMessengerKey,
    );


    final scaffoldMessengerKey = GlobalKey<ScaffoldMessengerState>();

In the main method use runAppWithDisposableCachedImage instead of runApp and pass it the scaffoldMessengerKey to initialize the package

the scaffoldMessengerKey.currentContext is used to precache the image ahead of being request in the ui, learn more about precacheImage.

    void main() {
      runAppWithDisposableCachedImage(
        const MyApp(),
        scaffoldMessengerKey: scaffoldMessengerKey,
      );
    }

If you are already using flutter_riverpod, you can pass ProviderScope arguments observers and overrides to the runAppWithDisposableCachedImage function.

Using DisposableCachedImageWidget #

Now your app is ready to use the package, use DisposableCachedImageWidget where you want to display images.

    DisposableCachedImageWidget(
    imageUrl: imageUrl,
    onLoading: (context) => const Center(
    child: Icon(Icons.downloading),
      ),
    onError: (context, reDownload) => Center(
    child: IconButton(
    onPressed: reDownload,
    icon: const Icon(Icons.download),
        ),
      ),
    );

How it works #

Stores and retrieves files using dart:io.

Disposing and change image state using flutter_riverpod with state_notifier.

Using dio instead of http To be able to cancel the download of the image if it's disposed during download.

Example app #

The example directory has a sample application that uses this plugin.

Roadmap #

Improve package documentation

Web support

Further improvements

37
likes
0
pub points
86%
popularity

Publisher

unverified uploader

Flutter package for displaying images from the Internet and keeping them in the cache directory.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

dio, flutter, flutter_riverpod, path_provider

More

Packages that depend on disposable_cached_images