Phase 0 — 共享组件: - EmptyStateWidget: 统一空状态 (icon + title + subtitle + CTA) - ErrorStateWidget: 统一错误状态 (message + retry) - SkeletonBox + SkeletonList: 统一骨架屏加载 (shimmer 动画) Phase 1 — Bug 修复: - 班级评论按 journalId 过滤,避免显示在错误日记卡片下 - moodCellColors key 修正: love/tired → angry/thinking - 日历非 CalendarLoaded 状态改为加载指示器 (不再 SizedBox.shrink) - 贴纸数统计改为 '--' 占位 (之前错误显示日记总数)
73 lines
2.1 KiB
Dart
73 lines
2.1 KiB
Dart
// 共享错误状态组件 — 统一所有页面的错误展示
|
|
//
|
|
// 使用: 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,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|