// 共享错误状态组件 — 统一所有页面的错误展示 // // 使用: ErrorStateWidget(message: '加载失败', onRetry: () => ...) // 样式: 云朵图标 + 错误信息 + 重试按钮 import 'package:flutter/material.dart'; import '../core/constants/design_tokens.dart'; import '../core/theme/app_radius.dart'; /// 统一错误状态组件 — 图标 + 错误信息 + 可选重试按钮 class ErrorStateWidget extends StatelessWidget { const ErrorStateWidget({ super.key, required this.message, this.onRetry, this.icon = Icons.cloud_off_rounded, }); /// 错误描述文字 final String message; /// 重试回调(不传则不显示重试按钮) final VoidCallback? onRetry; /// 主图标(默认云朵离线图标) final IconData icon; @override Widget build(BuildContext context) { final theme = Theme.of(context); return Center( child: Padding( padding: const EdgeInsets.symmetric( horizontal: DesignTokens.spacing24, vertical: DesignTokens.spacing40, ), child: Column( mainAxisSize: MainAxisSize.min, children: [ Icon( icon, size: 56, color: theme.colorScheme.onSurface.withValues(alpha: 0.25), ), const SizedBox(height: DesignTokens.spacing16), Text( message, style: theme.textTheme.bodyMedium?.copyWith( color: theme.colorScheme.onSurfaceVariant, ), textAlign: TextAlign.center, ), if (onRetry != null) ...[ const SizedBox(height: DesignTokens.spacing20), TextButton.icon( onPressed: onRetry, icon: const Icon(Icons.refresh_rounded, size: 18), label: const Text('重试'), style: TextButton.styleFrom( shape: RoundedRectangleBorder( borderRadius: AppRadius.pillBorder, ), ), ), ], ], ), ), ); } }