refactor(client): 商品/财务域颜色迁移到 context.tokens

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-06-24 23:57:49 +08:00
parent 7612495bbc
commit 7a92b0dfff
3 changed files with 142 additions and 137 deletions
+42 -40
View File
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../core/responsive/responsive.dart';
import '../../core/config/app_constants.dart';
import '../../core/theme/app_theme.dart';
import '../../core/theme/context_tokens.dart';
import '../../models/finance.dart';
import '../../providers/finance_provider.dart';
import '../../widgets/data_table_card.dart';
@@ -125,7 +125,7 @@ class _FinanceTabState extends ConsumerState<_FinanceTab> {
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('操作失败:$e'), backgroundColor: AppTheme.danger),
SnackBar(content: Text('操作失败:$e'), backgroundColor: context.tokens.danger),
);
}
}
@@ -159,7 +159,7 @@ class _FinanceTabState extends ConsumerState<_FinanceTab> {
'¥${r.balance.toStringAsFixed(2)}',
style: TextStyle(
fontSize: 13,
color: r.balance > 0 ? AppTheme.danger : AppTheme.textSecondary,
color: r.balance > 0 ? context.tokens.danger : context.tokens.muted,
fontWeight: FontWeight.w600,
),
)),
@@ -175,8 +175,8 @@ class _FinanceTabState extends ConsumerState<_FinanceTab> {
WriteGuard(
child: TextButton(
onPressed: () => _closeRecord(r),
child: const Text('结清',
style: TextStyle(fontSize: 13, color: AppTheme.success)),
child: Text('结清',
style: TextStyle(fontSize: 13, color: context.tokens.success)),
),
),
]
@@ -207,11 +207,11 @@ class _FinanceTabState extends ConsumerState<_FinanceTab> {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.cloud_off,
size: 40, color: AppTheme.textSecondary),
Icon(Icons.cloud_off,
size: 40, color: context.tokens.muted),
const SizedBox(height: 12),
const Text('暂无数据,网络不可用',
style: TextStyle(color: AppTheme.textSecondary)),
Text('暂无数据,网络不可用',
style: TextStyle(color: context.tokens.muted)),
const SizedBox(height: 12),
ElevatedButton(onPressed: _refetch, child: const Text('重试')),
],
@@ -296,8 +296,8 @@ class _FinanceTabState extends ConsumerState<_FinanceTab> {
r.refType != null && r.refId != null
? '${r.refType!.replaceAll('_', '-')}#${r.refId}'
: '-',
style: const TextStyle(
fontSize: 11, fontFamily: 'monospace', color: AppTheme.primary),
style: TextStyle(
fontSize: 11, fontFamily: 'monospace', color: context.tokens.primary),
));
case 'amount':
return DataCell(Text(
@@ -308,7 +308,7 @@ class _FinanceTabState extends ConsumerState<_FinanceTab> {
return DataCell(Text(
'¥${r.balance.toStringAsFixed(2)}',
style: TextStyle(
color: r.balance > 0 ? AppTheme.danger : AppTheme.textSecondary,
color: r.balance > 0 ? context.tokens.danger : context.tokens.muted,
fontWeight: FontWeight.w600,
),
));
@@ -322,8 +322,8 @@ class _FinanceTabState extends ConsumerState<_FinanceTab> {
width: 160,
child: Text(r.remark ?? '-',
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 12, color: AppTheme.textSecondary)),
style: TextStyle(
fontSize: 12, color: context.tokens.muted)),
));
case 'actions':
if ((r.type == 'payable' || r.type == 'receivable') &&
@@ -332,8 +332,8 @@ class _FinanceTabState extends ConsumerState<_FinanceTab> {
return DataCell(WriteGuard(
child: TextButton(
onPressed: () => _closeRecord(r),
child: const Text('结清',
style: TextStyle(fontSize: 12, color: AppTheme.success)),
child: Text('结清',
style: TextStyle(fontSize: 12, color: context.tokens.success)),
),
));
}
@@ -349,8 +349,8 @@ class _FinanceTabState extends ConsumerState<_FinanceTab> {
cells: List.generate(
visibleCols.length,
(i) => i == 0
? const DataCell(Text('暂无记录',
style: TextStyle(color: AppTheme.textSecondary)))
? DataCell(Text('暂无记录',
style: TextStyle(color: context.tokens.muted)))
: const DataCell(SizedBox()),
),
),
@@ -380,7 +380,7 @@ class _FinanceTabState extends ConsumerState<_FinanceTab> {
title: '合计金额',
value: '¥${(totalAmount / 10000).toStringAsFixed(2)}',
icon: Icons.account_balance_wallet,
color: AppTheme.primary,
color: context.tokens.primary,
width: w,
),
const SizedBox(width: 12),
@@ -388,7 +388,7 @@ class _FinanceTabState extends ConsumerState<_FinanceTab> {
title: '未结清',
value: '¥${(openAmount / 10000).toStringAsFixed(2)}',
icon: Icons.pending_actions,
color: AppTheme.danger,
color: context.tokens.danger,
width: w,
),
const SizedBox(width: 12),
@@ -396,12 +396,12 @@ class _FinanceTabState extends ConsumerState<_FinanceTab> {
title: '已结清',
value: '¥${(closedAmount / 10000).toStringAsFixed(2)}',
icon: Icons.check_circle,
color: AppTheme.success,
color: context.tokens.success,
width: w,
),
];
return Container(
color: AppTheme.background,
color: context.tokens.bg,
padding: const EdgeInsets.all(12),
child: context.isMobile
? SingleChildScrollView(
@@ -550,8 +550,9 @@ class _AddPaymentDialogState extends State<_AddPaymentDialog> {
final amount = double.tryParse(_amountCtrl.text.trim());
if (amount == null || amount <= 0) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('请输入有效金额'), backgroundColor: AppTheme.danger),
SnackBar(
content: const Text('请输入有效金额'),
backgroundColor: context.tokens.danger),
);
return;
}
@@ -569,14 +570,15 @@ class _AddPaymentDialogState extends State<_AddPaymentDialog> {
Navigator.of(context).pop();
widget.onSaved();
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('添加成功'), backgroundColor: AppTheme.success),
SnackBar(
content: const Text('添加成功'),
backgroundColor: context.tokens.success),
);
}
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('添加失败:$e'), backgroundColor: AppTheme.danger),
SnackBar(content: Text('添加失败:$e'), backgroundColor: context.tokens.danger),
);
}
} finally {
@@ -655,7 +657,7 @@ class _StatusBadge extends StatelessWidget {
child: Text(
isOpen ? '未结清' : '已结清',
style: TextStyle(
color: isOpen ? AppTheme.accent : AppTheme.textSecondary,
color: isOpen ? context.tokens.accent : context.tokens.muted,
fontSize: 12,
fontWeight: FontWeight.w500,
),
@@ -674,23 +676,23 @@ class _TypeBadge extends StatelessWidget {
switch (label) {
case '应收账款':
bg = const Color(0xFFE3F2FD);
fg = AppTheme.primary;
fg = context.tokens.primary;
break;
case '应付账款':
bg = const Color(0xFFFFEBEE);
fg = AppTheme.danger;
fg = context.tokens.danger;
break;
case '收款':
bg = const Color(0xFFE8F5E9);
fg = AppTheme.success;
fg = context.tokens.success;
break;
case '付款':
bg = const Color(0xFFFFF3E0);
fg = AppTheme.accent;
fg = context.tokens.accent;
break;
default:
bg = const Color(0xFFF5F5F5);
fg = AppTheme.textSecondary;
fg = context.tokens.muted;
}
return Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
@@ -724,9 +726,9 @@ class _SummaryCard extends StatelessWidget {
height: 72,
padding: const EdgeInsets.symmetric(horizontal: 16),
decoration: BoxDecoration(
color: AppTheme.surface,
color: context.tokens.surface,
borderRadius: BorderRadius.circular(4),
border: Border.all(color: AppTheme.border, width: 0.5),
border: Border.all(color: context.tokens.border, width: 0.5),
),
child: Row(
children: [
@@ -745,8 +747,8 @@ class _SummaryCard extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(title,
style: const TextStyle(
fontSize: 12, color: AppTheme.textSecondary)),
style: TextStyle(
fontSize: 12, color: context.tokens.muted)),
const SizedBox(height: 4),
Text(value,
style: TextStyle(
@@ -781,9 +783,9 @@ class _MonthSelector extends StatelessWidget {
height: 36,
padding: const EdgeInsets.symmetric(horizontal: 8),
decoration: BoxDecoration(
border: Border.all(color: AppTheme.border),
border: Border.all(color: context.tokens.border),
borderRadius: BorderRadius.circular(4),
color: AppTheme.surface,
color: context.tokens.surface,
),
child: DropdownButtonHideUnderline(
child: DropdownButton<String>(
@@ -794,7 +796,7 @@ class _MonthSelector extends StatelessWidget {
child: Text(m, style: const TextStyle(fontSize: 13))))
.toList(),
onChanged: (v) => onChanged(v!),
style: const TextStyle(fontSize: 13, color: AppTheme.textPrimary),
style: TextStyle(fontSize: 13, color: context.tokens.text),
),
),
);