Extract snackbar notifications to UISnackbars utility

Centralises all SnackBar calls behind UISnackbars.showError/showSuccess/
showWarning/showInfo, each themed via AppColorExtension. New warning and
info colour tokens added to both themes. Calling any method clears any
visible snackbar before showing the new one.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
rzuasti
2026-05-27 17:43:01 -04:00
co-authored by Claude Sonnet 4.6
parent 3094753587
commit 07f7d54531
8 changed files with 165 additions and 178 deletions
+26 -17
View File
@@ -3,30 +3,39 @@ import '../theme/app_colors.dart';
class UISnackbars {
static void showError(BuildContext context, String message) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
message,
style: TextStyle(color: Theme.of(context).colorScheme.onError),
),
behavior: SnackBarBehavior.floating,
showCloseIcon: true,
backgroundColor: Theme.of(context).colorScheme.error,
),
);
final colorScheme = Theme.of(context).colorScheme;
_show(context, message, colorScheme.error, colorScheme.onError);
}
static void showSuccess(BuildContext context, String message) {
final appColors = Theme.of(context).extension<AppColorExtension>()!;
ScaffoldMessenger.of(context).showSnackBar(
_show(context, message, appColors.success, appColors.onSuccess);
}
static void showWarning(BuildContext context, String message) {
final appColors = Theme.of(context).extension<AppColorExtension>()!;
_show(context, message, appColors.warning, appColors.onWarning);
}
static void showInfo(BuildContext context, String message) {
final appColors = Theme.of(context).extension<AppColorExtension>()!;
_show(context, message, appColors.info, appColors.onInfo);
}
static void _show(
BuildContext context,
String message,
Color background,
Color foreground,
) {
final messenger = ScaffoldMessenger.of(context);
messenger.clearSnackBars();
messenger.showSnackBar(
SnackBar(
content: Text(
message,
style: TextStyle(color: appColors.onSuccess),
),
content: Text(message, style: TextStyle(color: foreground)),
behavior: SnackBarBehavior.floating,
showCloseIcon: true,
backgroundColor: appColors.success,
backgroundColor: background,
),
);
}