import 'package:flutter/material.dart'; /// 空状态视图组件 class EmptyView extends StatelessWidget { final String? message; final String? imagePath; final IconData? icon; final Color? iconColor; final double? iconSize; final Widget? action; final EdgeInsets? padding; const EmptyView({ super.key, this.message, this.imagePath, this.icon, this.iconColor, this.iconSize, this.action, this.padding, }); @override Widget build(BuildContext context) { return Padding( padding: padding ?? const EdgeInsets.all(24.0), child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ // 图标或图片 if (imagePath != null) Image.asset( imagePath!, width: 120, height: 120, ) else if (icon != null) Icon( icon, size: iconSize ?? 64, color: iconColor ?? Theme.of(context).colorScheme.onSurface.withOpacity(0.4), ) else Icon( Icons.inbox_outlined, size: iconSize ?? 64, color: Theme.of(context).colorScheme.onSurface.withOpacity(0.4), ), const SizedBox(height: 16), // 提示文字 if (message != null) Text( message!, style: Theme.of(context).textTheme.bodyMedium?.copyWith( color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6), ), textAlign: TextAlign.center, ) else Text( '暂无数据', style: Theme.of(context).textTheme.bodyMedium?.copyWith( color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6), ), textAlign: TextAlign.center, ), // 操作按钮 if (action != null) ...[ const SizedBox(height: 24), action!, ], ], ), ), ); } }