Files
Aq-Accounting-Flutter/lib/widgets/state_views.dart
T
2026-09-24 14:24:34 +08:00

113 lines
3.1 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:flutter/material.dart';
import 'cute_icon.dart';
/// 加载态
class LoadingView extends StatelessWidget {
const LoadingView({super.key, this.tip = '加载中...', this.padding = const EdgeInsets.all(40)});
final String tip;
final EdgeInsetsGeometry padding;
@override
Widget build(BuildContext context) {
return Padding(
padding: padding,
child: Column(
children: [
const SizedBox(
width: 26,
height: 26,
child: CircularProgressIndicator(strokeWidth: 2.5, color: Color(0xFFC8956E)),
),
const SizedBox(height: 12),
Text(tip, style: const TextStyle(fontSize: 13, color: Color(0xFF8D6E63))),
],
),
);
}
}
/// 错误态(可带重试)
class ErrorView extends StatelessWidget {
const ErrorView({super.key, required this.message, this.onRetry});
final String message;
final VoidCallback? onRetry;
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.white.withValues(alpha: 0.85),
borderRadius: BorderRadius.circular(14),
),
child: Column(
children: [
const CuteIcon('error', size: 32),
const SizedBox(height: 10),
Text(
message,
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 13, color: Color(0xFF8D6E63)),
),
if (onRetry != null) ...[
const SizedBox(height: 12),
OutlinedButton(
onPressed: onRetry,
style: OutlinedButton.styleFrom(
foregroundColor: const Color(0xFFC8956E),
side: const BorderSide(color: Color(0xFFC8956E)),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(18)),
),
child: const Text('重试'),
),
],
],
),
);
}
}
/// 空状态
///
/// [icon] 传图标名(见 [cuteIconNames]);为了兼容以前传 emoji 的调用点,
/// 走的是 [resolveIconName],emoji 和未知值都能落到一个兜底图标上。
class EmptyView extends StatelessWidget {
const EmptyView({
super.key,
this.icon = 'inbox',
required this.title,
this.tip,
this.padding = const EdgeInsets.symmetric(vertical: 40),
});
final String icon;
final String title;
final String? tip;
final EdgeInsetsGeometry padding;
@override
Widget build(BuildContext context) {
return Padding(
padding: padding,
child: Column(
children: [
CuteIcon(icon, size: 46),
const SizedBox(height: 12),
Text(title, style: const TextStyle(fontSize: 15, color: Color(0xFF5D4037))),
if (tip != null) ...[
const SizedBox(height: 6),
Text(
tip!,
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 12.5, color: Color(0xFFBCAAA4)),
),
],
],
),
);
}
}