105 lines
3.1 KiB
Dart
105 lines
3.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../../app/theme/app_colors.dart';
|
|
import '../../app/theme/app_typography.dart';
|
|
import '../../app/theme/app_spacing.dart';
|
|
|
|
/// 空状态页组件
|
|
///
|
|
/// 各场景的空状态插画 + 引导操作
|
|
/// 使用场景:列表为空、搜索无结果、网络错误
|
|
class EmptyState extends StatelessWidget {
|
|
final IconData icon;
|
|
final String title;
|
|
final String? subtitle;
|
|
final String? actionText;
|
|
final VoidCallback? onAction;
|
|
|
|
const EmptyState({
|
|
super.key,
|
|
required this.icon,
|
|
required this.title,
|
|
this.subtitle,
|
|
this.actionText,
|
|
this.onAction,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 40, vertical: 60),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Container(
|
|
width: 80,
|
|
height: 80,
|
|
decoration: BoxDecoration(
|
|
color: AppColors.primarySurface,
|
|
shape: BoxShape.circle,
|
|
),
|
|
child: Icon(icon, size: 36, color: AppColors.primary.withValues(alpha: 0.5)),
|
|
),
|
|
const SizedBox(height: AppSpacing.xxl),
|
|
Text(
|
|
title,
|
|
style: AppTypography.h3.copyWith(color: AppColors.textSecondary),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
if (subtitle != null) ...[
|
|
const SizedBox(height: AppSpacing.sm),
|
|
Text(
|
|
subtitle!,
|
|
style: AppTypography.bodySmall,
|
|
textAlign: TextAlign.center,
|
|
),
|
|
],
|
|
if (actionText != null && onAction != null) ...[
|
|
const SizedBox(height: AppSpacing.xxl),
|
|
ElevatedButton(
|
|
onPressed: onAction,
|
|
child: Text(actionText!),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
// 快捷工厂方法
|
|
factory EmptyState.noCoupons({VoidCallback? onBrowse}) => EmptyState(
|
|
icon: Icons.confirmation_number_outlined,
|
|
title: '还没有券',
|
|
subtitle: '去市场看看有什么好券吧',
|
|
actionText: '去逛逛',
|
|
onAction: onBrowse,
|
|
);
|
|
|
|
factory EmptyState.noOrders() => const EmptyState(
|
|
icon: Icons.receipt_long_outlined,
|
|
title: '暂无交易记录',
|
|
subtitle: '完成首笔交易后这里会显示记录',
|
|
);
|
|
|
|
factory EmptyState.noResults() => const EmptyState(
|
|
icon: Icons.search_off_rounded,
|
|
title: '没有找到结果',
|
|
subtitle: '换个关键词试试',
|
|
);
|
|
|
|
factory EmptyState.noMessages() => const EmptyState(
|
|
icon: Icons.notifications_none_rounded,
|
|
title: '暂无消息',
|
|
subtitle: '交易通知和系统公告会显示在这里',
|
|
);
|
|
|
|
factory EmptyState.networkError({VoidCallback? onRetry}) => EmptyState(
|
|
icon: Icons.wifi_off_rounded,
|
|
title: '网络连接失败',
|
|
subtitle: '请检查网络设置后重试',
|
|
actionText: '重试',
|
|
onAction: onRetry,
|
|
);
|
|
}
|