| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- 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!,
- ],
- ],
- ),
- ),
- );
- }
- }
|