showCacheStatsSummary static method
- BuildContext context, {
- required Map<
String, bool> categoryResults, - required Duration totalTime,
Shows cache statistics summary.
Implementation
static void showCacheStatsSummary(
BuildContext context, {
required Map<String, bool> categoryResults,
required Duration totalTime,
}) {
final cacheHits =
categoryResults.values.where((fromCache) => fromCache).length;
final totalCategories = categoryResults.length;
final networkCalls = totalCategories - cacheHits;
final String message;
final Color backgroundColor;
if (cacheHits == totalCategories) {
message =
'All $totalCategories categories loaded from cache instantly! ⚡';
backgroundColor = Colors.green;
} else if (cacheHits > 0) {
message =
'$cacheHits cached, $networkCalls from network in ${totalTime.inMilliseconds}ms';
backgroundColor = Colors.blue;
} else {
message =
'All $totalCategories categories downloaded from network in ${totalTime.inMilliseconds}ms';
backgroundColor = Colors.orange;
}
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Row(
children: [
Icon(
cacheHits == totalCategories ? Icons.offline_bolt : Icons.wifi,
color: Colors.white,
size: 16,
),
const SizedBox(width: 8),
Expanded(
child: Text(message, style: const TextStyle(color: Colors.white)),
),
],
),
backgroundColor: backgroundColor,
duration: const Duration(seconds: 3),
behavior: SnackBarBehavior.floating,
margin: const EdgeInsets.all(16),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
),
);
}