import 'package:flutter/material.dart'; import '../core/app_colors.dart'; /// 统一的"加载失败"状态——与 AppEmptyState 风格一致,区别在于明确表达"出错了,可重试", /// 避免把网络/服务失败误显示成"暂无数据"。 class AppErrorState extends StatelessWidget { final String title; final String? subtitle; final VoidCallback? onRetry; const AppErrorState({ super.key, this.title = '加载失败', this.subtitle = '网络异常或服务暂时不可用,请稍后重试', this.onRetry, }); @override Widget build(BuildContext context) { return Center( child: Padding( padding: const EdgeInsets.all(48), child: Column( mainAxisSize: MainAxisSize.min, children: [ Container( width: 80, height: 80, decoration: BoxDecoration( gradient: AppColors.softGlassGradient, borderRadius: BorderRadius.circular(40), border: Border.all(color: AppColors.borderLight), boxShadow: AppColors.cardShadowLight, ), child: const Icon( Icons.cloud_off_outlined, size: 34, color: AppColors.primaryDark, ), ), const SizedBox(height: 18), Text( title, style: const TextStyle( fontSize: 18, fontWeight: FontWeight.w700, color: AppColors.textPrimary, ), textAlign: TextAlign.center, ), if (subtitle != null) ...[ const SizedBox(height: 6), Text( subtitle!, style: const TextStyle( fontSize: 14, color: AppColors.textSecondary, ), textAlign: TextAlign.center, ), ], if (onRetry != null) ...[ const SizedBox(height: 20), OutlinedButton.icon( onPressed: onRetry, icon: const Icon(Icons.refresh, size: 18), label: const Text('重试'), style: OutlinedButton.styleFrom( foregroundColor: AppColors.primaryDark, side: const BorderSide(color: AppColors.borderLight), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(12), ), ), ), ], ], ), ), ); } }