mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
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>
43 lines
1.3 KiB
Dart
43 lines
1.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../theme/app_colors.dart';
|
|
|
|
class UISnackbars {
|
|
static void showError(BuildContext context, String message) {
|
|
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>()!;
|
|
_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: foreground)),
|
|
behavior: SnackBarBehavior.floating,
|
|
showCloseIcon: true,
|
|
backgroundColor: background,
|
|
),
|
|
);
|
|
}
|
|
}
|