cross_cache 1.0.2
cross_cache: ^1.0.2 copied to clipboard
Cross-platform cache manager for Flutter using IndexedDB for web, file system for mobile and desktop, and Dio for network requests. #cache #indexeddb #dio
import 'package:flutter/material.dart';
import 'package:cross_cache/cross_cache.dart';
class MyWidget extends StatefulWidget {
@override
_MyWidgetState createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> {
final _cache = CrossCache(); // Create an instance
@override
void dispose() {
_cache.dispose(); // Dispose the cache
super.dispose();
}
@override
Widget build(BuildContext context) {
return Image(
image: CachedNetworkImage(
'https://example.com/image.jpg',
_cache, // Pass the cache instance
headers: {'Authorization': 'Bearer YOUR_TOKEN'}, // Optional headers
),
loadingBuilder: (context, child, loadingProgress) {
if (loadingProgress == null) return child;
return Center(
child: CircularProgressIndicator(
value: loadingProgress.expectedTotalBytes != null
? loadingProgress.cumulativeBytesLoaded / loadingProgress.expectedTotalBytes!
: null,
),
);
},
errorBuilder: (context, error, stackTrace) => Icon(Icons.error),
);
}
}