showCachePerformanceToast static method
Shows a toast message about cache performance.
Implementation
static void showCachePerformanceToast(
BuildContext context, {
required bool fromCache,
required String category,
Duration? cacheAge,
int? movieCount,
bool showSuccessToasts = true,
}) {
if (!showSuccessToasts && fromCache) return;
final String message;
final Color backgroundColor;
final IconData icon;
if (fromCache) {
final ageText = cacheAge != null ? _formatCacheAge(cacheAge) : '';
final countText = movieCount != null ? ' ($movieCount movies)' : '';
message = 'Loaded $category from cache instantly! $ageText$countText';
backgroundColor = Colors.green;
icon = Icons.offline_bolt;
} else {
final countText = movieCount != null ? ' ($movieCount movies)' : '';
message = 'Downloaded fresh $category from network$countText';
backgroundColor = Colors.blue;
icon = Icons.wifi;
}
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Row(
children: [
Icon(icon, color: Colors.white, size: 16),
const SizedBox(width: 8),
Expanded(
child: Text(message, style: const TextStyle(color: Colors.white)),
),
],
),
backgroundColor: backgroundColor,
duration:
fromCache ? const Duration(seconds: 2) : const Duration(seconds: 3),
behavior: SnackBarBehavior.floating,
margin: const EdgeInsets.all(16),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
),
);
}