This package is no longer maintained, because it has been moved to a new location: flutter_cached
When building a screen that displays a cached list of items, there are many special cases to think about.
This package tries to make implementing cached ListViews as easy as possible.
|loading with no data in cache||loading with data in cache||loading successful|
|error with no data in cache||error with data in cache||no data available|
First, create a
CacheController. This will be the class that orchestrates the fetching of data.
var cacheController = CacheController<Item>( // Does the actual work and returns a Future<List<Item>>. fetcher: _downloadData, // Asynchronously saves a List<Item> to the cache. saveToCache: _saveToCache, // Asynchronously loads a List<Item> from the cache. loadFromCache: _loadFromCache, );
Then you can create a
CachedListView in your widget tree:
CachedListView( controller: cacheController, itemBuilder: (context, item) => ..., errorBannerBuilder: (context, error) => ..., errorScreenBuilder: (context, error) => ..., emptyStateBuilder: (context) => ..., ),