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

A lightweight Flutter package for caching network images locally with offline support and smart sync using update timestamps.

image_cache_sync #

A lightweight Flutter package for caching network images locally with offline support and smart synchronization using update timestamps.

This package is designed to efficiently download, store, and reuse images while keeping them in sync with backend updates.


๐Ÿš€ Features #

  • ๐Ÿ“ฅ Download and cache images locally
  • ๐Ÿ’พ Persistent storage using Hive
  • ๐Ÿ”„ Smart sync using updatedAt timestamps
  • ๐Ÿ“ฆ Bulk image handling (pagination friendly)
  • ๐Ÿ“ด Offline support (works without internet after first load)
  • ๐Ÿงน Cache management (clear/delete images)
  • ๐ŸŽจ Easy-to-use Flutter widget (CachedImageView)
  • โšก Efficient network usage (downloads only when needed)

๐Ÿง  Why use this package? #

In many apps, images are:

  • Loaded repeatedly from network โŒ
  • Not available offline โŒ
  • Not synced with backend updates โŒ

This package solves that by:

  • Caching images locally
  • Reusing cached images
  • Updating only when required

๐Ÿ“ฆ Installation #

Add this to your pubspec.yaml:

dependencies:
  image_cache_sync: ^0.0.1

Then run:

flutter pub get

๐Ÿงช Usage #

CachedImageView(
  id: "1",
  url: "https://your-api.com/image.jpg",
  updatedAt: DateTime(2024, 1, 1),
)

๐Ÿ”น 2. Fetch Image Manually #

final manager = ImageCacheManager();

final image = await manager.fetchImage(
  id: "1",
  url: "https://your-api.com/image.jpg",
  updatedAt: DateTime(2024, 1, 1),
);

print(image.localPath);

๐Ÿ”น 3. Bulk Sync (Pagination Friendly) #

final manager = ImageCacheManager();

final images = await manager.syncImages([
  ImageItem(
    id: "1",
    url: "https://your-api.com/image.jpg",
    localPath: "",
    updatedAt: DateTime(2024, 1, 1),
  ),
]);

๐Ÿ”น 4. Clear Cache #

final manager = ImageCacheManager();

await manager.clearAll();

๐Ÿ”น 5. Get Cached Image Only #

final cached = await manager.getCached("1");

๐Ÿง  How It Works #

Step 1: Check Cache #

The package checks if the image already exists locally.

Step 2: Compare Timestamp #

It compares updatedAt from API with cached value.

Step 3: Decide Action #

Condition Action
Not cached Download image
Cached + same updatedAt Use local image
Cached + updatedAt changed Re-download

Step 4: Store Data #

  • Image file โ†’ local storage
  • Metadata โ†’ Hive database

๐Ÿ“ฑ Pagination Support #

This package works seamlessly with paginated APIs.

  • Sync happens per item (not per page)
  • Only current page needs syncing
  • Efficient for large datasets

๐Ÿ“ด Offline Support #

Once images are cached:

  • No internet required
  • Images load instantly
  • Works even in airplane mode

๐Ÿงน Cache Management #

Clear all cached data #

await manager.clearAll();

This will:

  • Remove all images from storage
  • Clear Hive database

๐ŸŽฏ Use Cases #

  • ๐Ÿ›’ E-commerce apps
  • ๐Ÿ“ฐ News apps
  • ๐Ÿ“ธ Gallery apps
  • ๐Ÿ“ฑ Social media feeds
  • ๐Ÿ“ก Offline-first apps

โš ๏ธ Important Notes #

  • updatedAt must come from your API
  • Changing updatedAt triggers re-download
  • Ensure id is unique for each image
  • URL is required for sync functionality

๐Ÿ“Š Example Flow #

  1. App loads image โ†’ downloads & caches
  2. App restarts โ†’ loads from cache
  3. Backend updates image โ†’ updatedAt changes
  4. Package detects change โ†’ re-downloads

๐Ÿ”ฎ Future Improvements (Planned) #

  • Placeholder & error widgets
  • Retry mechanism
  • Cache size control
  • Performance optimizations

๐Ÿค Contributing #

Contributions are welcome! Feel free to open issues or submit pull requests.


๐Ÿ“„ License #

MIT License

1
likes
150
points
119
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A lightweight Flutter package for caching network images locally with offline support and smart sync using update timestamps.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, hive_ce, hive_ce_flutter, http, path_provider

More

Packages that depend on image_cache_sync