cachet_image 0.1.0
cachet_image: ^0.1.0 copied to clipboard
A modern, isolate-friendly network image loader with disk caching, structured error handling, and stream-based load states for Flutter.
import 'package:cachet_image/cachet_image.dart';
import 'package:flutter/material.dart';
void main() {
// Optional: tune cache limits once at startup.
CachetCacheManager.configure(
maxCacheBytes: 100 * 1024 * 1024, // 100 MB
maxAge: const Duration(days: 14),
);
runApp(const CachetExampleApp());
}
class CachetExampleApp extends StatelessWidget {
const CachetExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'cachet_image example',
home: Scaffold(
appBar: AppBar(title: const Text('cachet_image')),
body: GridView.builder(
padding: const EdgeInsets.all(8),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 8,
mainAxisSpacing: 8,
),
itemCount: 20,
itemBuilder: (context, index) => ClipRRect(
borderRadius: BorderRadius.circular(8),
child: CachetImage(
url: 'https://picsum.photos/seed/$index/400/400',
fit: BoxFit.cover,
placeholderBuilder: (context, progress) => Container(
color: Colors.grey.shade200,
child: Center(
child: CircularProgressIndicator(value: progress),
),
),
errorBuilder: (context, failure) => Container(
color: Colors.grey.shade200,
child: Center(
child: Text(
switch (failure) {
CachetNetworkFailure() => 'Network error',
CachetDecodeFailure() => 'Decode error',
CachetCacheFailure() => 'Cache error',
},
),
),
),
),
),
),
),
);
}
}