mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
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:
co-authored by
Claude Sonnet 4.6
parent
3094753587
commit
07f7d54531
@@ -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,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user