flutter_assets_cache 0.0.1
flutter_assets_cache: ^0.0.1 copied to clipboard
Efficiently cache images and SVG assets in Flutter apps, with support for both local and network sources, customizable cache management, and performance metrics.
Flutter Assets Cache #
This Dart package provides a convenient way to cache images and SVG assets in Flutter applications, supporting both local and network sources. It utilizes a custom cache manager to efficiently manage asset caching, reducing load times and improving app performance.
Features #
- Caching of network images with a custom cache manager.
- Support for both SVG and traditional image formats.
- Placeholder widget display while images are loading.
- Performance metrics logging for cache hits and misses.
- Easy integration with existing Flutter projects.
Getting Started #
To use this package in your project, follow these steps:
-
Add the dependency: Include
flutter_assets_cachein yourpubspec.yamlfile.dependencies: flutter_assets_cache: latest_version -
Import the package: Add the following import to your Dart file.
import 'package:flutter_assets_cache/flutter_assets_cache.dart'; -
Use the
getImageWidgetfunction: Replace your image loading logic with calls togetImageWidget, specifying the image URL and any optional parameters like height, width, and fit.Widget myImageWidget = getImageWidget( 'https://example.com/myimage.png', height: 100, width: 100, fit: BoxFit.cover, );
Example Usage #
Below is an example of how to use the getImageWidget function to load an image from a network source with caching:
class MyImageWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
child: getImageWidget(
'https://example.com/image.svg',
height: 200,
width: 200,
fit: BoxFit.fill,
),
);
}
}