2026-03-03 12:20:57 -05:00
|
|
|
import 'package:flutter/material.dart';
|
2026-05-27 11:38:16 -04:00
|
|
|
import '../theme/app_colors.dart';
|
2026-03-03 12:20:57 -05:00
|
|
|
|
2026-06-01 07:09:24 -04:00
|
|
|
enum _Severity { error, success, warning, info }
|
|
|
|
|
|
2026-03-03 12:20:57 -05:00
|
|
|
class UISnackbars {
|
2026-06-01 07:09:24 -04:00
|
|
|
static void showError(BuildContext context, String message) =>
|
|
|
|
|
_show(context, message, _Severity.error);
|
2026-03-03 12:20:57 -05:00
|
|
|
|
2026-06-01 07:09:24 -04:00
|
|
|
static void showSuccess(BuildContext context, String message) =>
|
|
|
|
|
_show(context, message, _Severity.success);
|
2026-05-27 17:43:01 -04:00
|
|
|
|
2026-06-01 07:09:24 -04:00
|
|
|
static void showWarning(BuildContext context, String message) =>
|
|
|
|
|
_show(context, message, _Severity.warning);
|
2026-05-27 17:43:01 -04:00
|
|
|
|
2026-06-01 07:09:24 -04:00
|
|
|
static void showInfo(BuildContext context, String message) =>
|
|
|
|
|
_show(context, message, _Severity.info);
|
|
|
|
|
|
|
|
|
|
static void _show(BuildContext context, String message, _Severity severity) {
|
|
|
|
|
final theme = Theme.of(context);
|
|
|
|
|
final colors = theme.extension<AppColorExtension>()!;
|
|
|
|
|
final (background, foreground) = switch (severity) {
|
|
|
|
|
_Severity.error => (theme.colorScheme.error, theme.colorScheme.onError),
|
|
|
|
|
_Severity.success => (colors.success, colors.onSuccess),
|
|
|
|
|
_Severity.warning => (colors.warning, colors.onWarning),
|
|
|
|
|
_Severity.info => (colors.info, colors.onInfo),
|
|
|
|
|
};
|
2026-05-27 17:43:01 -04:00
|
|
|
|
|
|
|
|
final messenger = ScaffoldMessenger.of(context);
|
|
|
|
|
messenger.clearSnackBars();
|
|
|
|
|
messenger.showSnackBar(
|
2026-03-03 12:20:57 -05:00
|
|
|
SnackBar(
|
2026-05-27 17:43:01 -04:00
|
|
|
content: Text(message, style: TextStyle(color: foreground)),
|
2026-03-03 12:20:57 -05:00
|
|
|
behavior: SnackBarBehavior.floating,
|
|
|
|
|
showCloseIcon: true,
|
2026-05-27 17:43:01 -04:00
|
|
|
backgroundColor: background,
|
2026-03-03 12:20:57 -05:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|