cached_future_builder_plus
A Flutter widget that extends FutureBuilder with intelligent caching capabilities.
Installation
Add this package to your pubspec.yaml:
flutter pub add cached_future_builder_plus
Usage
Replace your existing FutureBuilder with CachedFutureBuilderPlus:
import 'package:cached_future_builder_plus/cached_future_builder_plus.dart';
CachedFutureBuilderPlus<Map<String, dynamic>?>(
cacheKey: 'todo:1', // Unique key for caching
cachePolicy: CachePolicy.cacheThenNetwork, // Choose your cache strategy
future: _fetchTodo(), // Your existing future
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator();
}
final data = snapshot.data;
if (data == null) {
return const Text('No data available');
}
return Text('Title: ${data['title']}');
},
)
Cache Policies
CachePolicy.cacheOnly: Only use cached dataCachePolicy.networkOnly: Only fetch from networkCachePolicy.cacheFirst: Use cache if available, otherwise networkCachePolicy.networkFirst: Try network first, fallback to cacheCachePolicy.cacheThenNetwork: Show cache immediately, then update with network data
Additional information
This package is built on top of the api_repo package for caching functionality. The cache key should be unique for each data source (recommended: use the API URL including query parameters).
For more information, issues, or contributions, please visit the package repository.