Files
oott/frontend/lib/utils/ui_snackbars.dart
T
rzuastiandClaude Opus 4.7 17712c25f1 Collapse scanner-card and pagination duplication into shared widgets
Extract ScannerStatusCard<T> and PaginationBar so the ARP/mDNS cards and
the two paginated lists share one implementation each. Also fold the
four UISnackbars methods over a severity enum and fix Notification.toJson
serializing a method tear-off instead of the enum name.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-01 07:09:24 -04:00

41 lines
1.4 KiB
Dart

import 'package:flutter/material.dart';
import '../theme/app_colors.dart';
enum _Severity { error, success, warning, info }
class UISnackbars {
static void showError(BuildContext context, String message) =>
_show(context, message, _Severity.error);
static void showSuccess(BuildContext context, String message) =>
_show(context, message, _Severity.success);
static void showWarning(BuildContext context, String message) =>
_show(context, message, _Severity.warning);
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),
};
final messenger = ScaffoldMessenger.of(context);
messenger.clearSnackBars();
messenger.showSnackBar(
SnackBar(
content: Text(message, style: TextStyle(color: foreground)),
behavior: SnackBarBehavior.floating,
showCloseIcon: true,
backgroundColor: background,
),
);
}
}