Files
sm-emby-share/lib/shared/widgets/app_inline_alert.dart
T

89 lines
2.6 KiB
Dart
Raw Normal View History

2026-07-14 11:11:36 +08:00
import 'package:flutter/material.dart';
enum AppAlertTone { error, warning, info, success }
class AppInlineAlert extends StatelessWidget {
final String message;
final AppAlertTone tone;
final IconData? icon;
const AppInlineAlert({
super.key,
required this.message,
this.tone = AppAlertTone.error,
this.icon,
});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final colors = _colors(theme.colorScheme);
return Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
decoration: BoxDecoration(
color: colors.background,
borderRadius: BorderRadius.circular(6),
border: Border.all(color: colors.foreground.withValues(alpha: 0.16)),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(icon ?? _defaultIcon, size: 16, color: colors.foreground),
const SizedBox(width: 8),
Expanded(
child: Text(
message,
style: theme.textTheme.bodySmall?.copyWith(
color: colors.foreground,
height: 1.35,
),
),
),
],
),
);
}
IconData get _defaultIcon => switch (tone) {
AppAlertTone.error => Icons.error_outline,
AppAlertTone.warning => Icons.warning_amber_rounded,
AppAlertTone.info => Icons.info_outline,
AppAlertTone.success => Icons.check_circle_outline,
};
({Color background, Color foreground}) _colors(ColorScheme scheme) {
final isDark = scheme.brightness == Brightness.dark;
return switch (tone) {
AppAlertTone.error => (
background: scheme.errorContainer,
foreground: scheme.onErrorContainer,
),
AppAlertTone.warning =>
isDark
? (
background: const Color(0xFF3A2E12),
foreground: const Color(0xFFFFD68A),
)
: (
background: const Color(0xFFFFF3D6),
foreground: const Color(0xFF7A4D00),
),
AppAlertTone.info => (
background: scheme.secondaryContainer,
foreground: scheme.onSecondaryContainer,
),
AppAlertTone.success =>
isDark
? (
background: const Color(0xFF12331F),
foreground: const Color(0xFF7FE3A8),
)
: (
background: const Color(0xFFDDF7E8),
foreground: const Color(0xFF0B6B3A),
),
};
}
}