/// 错误态(UI-01):错误图标 + 说明 + 重试按钮(主强调)。 /// /// 用于加载失败等需要用户处理的场景。与 EmptyState 的区别:错误态有 /// 明确的重试动作(主按钮 + 刷新图标),文案为错误色语义;空态无重试。 /// 重试文案来自语言资源([AppLocalizations.retry])。 library; import 'package:flutter/material.dart'; import '../../l10n/app_localizations.dart'; import '../tokens.dart'; /// 错误态视图。 class ErrorState extends StatelessWidget { const ErrorState({ required this.message, required this.onRetry, this.icon, super.key, }); /// 错误说明(调用方本地化,如错误码映射文案)。 final String message; /// 重试回调。 final VoidCallback onRetry; /// 覆盖主题图标(默认 [Icons.cloud_off],加载失败语义)。 final IconData? icon; @override Widget build(BuildContext context) { final theme = Theme.of(context); final errorColor = theme.brightness == Brightness.light ? kColorError : kColorErrorDark; return Center( child: Padding( padding: const EdgeInsets.all(kSpace24), child: Column( mainAxisSize: MainAxisSize.min, children: [ Icon(icon ?? Icons.cloud_off, size: 48, color: errorColor), const SizedBox(height: kSpace12), Text( message, textAlign: TextAlign.center, style: theme.textTheme.bodyLarge?.copyWith( color: theme.colorScheme.onSurfaceVariant, ), ), const SizedBox(height: kSpace16), FilledButton.icon( onPressed: onRetry, icon: const Icon(Icons.refresh), label: Text(AppLocalizations.of(context).retry), ), ], ), ), ); } }