import 'package:flutter/material.dart'; import 'package:sino_med_cloud/l10n/app_localizations.dart'; /// 错误状态视图组件 class ErrorView extends StatelessWidget { final String? message; final String? error; final VoidCallback? onRetry; final IconData? icon; final Color? iconColor; final EdgeInsets? padding; const ErrorView({ super.key, this.message, this.error, this.onRetry, this.icon, this.iconColor, this.padding, }); @override Widget build(BuildContext context) { final l10n = AppLocalizations.of(context)!; return Padding( padding: padding ?? const EdgeInsets.all(24.0), child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ // 错误图标 Icon( icon ?? Icons.error_outline, size: 64, color: iconColor ?? Theme.of(context).colorScheme.error, ), const SizedBox(height: 16), // 错误提示 Text( message ?? l10n.loadFailed, style: Theme.of(context).textTheme.titleMedium?.copyWith( color: Theme.of(context).colorScheme.onSurface, ), textAlign: TextAlign.center, ), // 详细错误信息(可选) if (error != null) ...[ const SizedBox(height: 8), Text( error!, style: Theme.of(context).textTheme.bodySmall?.copyWith( color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6), ), textAlign: TextAlign.center, maxLines: 3, overflow: TextOverflow.ellipsis, ), ], // 重试按钮 if (onRetry != null) ...[ const SizedBox(height: 24), ElevatedButton.icon( onPressed: onRetry, icon: const Icon(Icons.refresh), label: Text(l10n.retry), style: ElevatedButton.styleFrom( padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12), ), ), ], ], ), ), ); } }