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
@@ -11,7 +11,7 @@ import '../../core/utils/print_util.dart';
import '../../widgets/label_preview_dialog.dart';
import '../../widgets/fullscreen_image_viewer.dart';
import '../../widgets/write_guard.dart';
import '../../core/theme/app_theme.dart';
import '../../core/theme/context_tokens.dart';
import '../../models/product.dart';
import '../../models/product_image.dart';
import '../../providers/product_provider.dart';
@@ -87,7 +87,7 @@ class _ProductDetailScreenState extends ConsumerState<ProductDetailScreen> {
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('保存失败:$e'), backgroundColor: AppTheme.danger),
SnackBar(content: Text('保存失败:$e'), backgroundColor: context.tokens.danger),
);
}
} finally {
@@ -175,7 +175,7 @@ class _ProductDetailScreenState extends ConsumerState<ProductDetailScreen> {
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('上传失败:$e'), backgroundColor: AppTheme.danger),
SnackBar(content: Text('上传失败:$e'), backgroundColor: context.tokens.danger),
);
}
} finally {
@@ -190,7 +190,7 @@ class _ProductDetailScreenState extends ConsumerState<ProductDetailScreen> {
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('删除失败:$e'), backgroundColor: AppTheme.danger),
SnackBar(content: Text('删除失败:$e'), backgroundColor: context.tokens.danger),
);
}
}
@@ -234,7 +234,7 @@ class _ProductDetailScreenState extends ConsumerState<ProductDetailScreen> {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.error_outline, size: 40, color: AppTheme.danger),
Icon(Icons.error_outline, size: 40, color: context.tokens.danger),
const SizedBox(height: 12),
Text('加载失败:${snap.error}'),
const SizedBox(height: 12),
@@ -300,11 +300,11 @@ class _ProductDetailScreenState extends ConsumerState<ProductDetailScreen> {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('图片',
Text('图片',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: AppTheme.textSecondary)),
color: context.tokens.muted)),
const SizedBox(height: 8),
SizedBox(
height: 120,
@@ -330,10 +330,10 @@ class _ProductDetailScreenState extends ConsumerState<ProductDetailScreen> {
),
),
if (p.images.isEmpty && !_uploading)
const Padding(
padding: EdgeInsets.only(top: 4),
Padding(
padding: const EdgeInsets.only(top: 4),
child: Text('暂无图片,点击 + 上传',
style: TextStyle(fontSize: 12, color: AppTheme.textSecondary)),
style: TextStyle(fontSize: 12, color: context.tokens.muted)),
),
],
);
@@ -348,8 +348,8 @@ class _ProductDetailScreenState extends ConsumerState<ProductDetailScreen> {
SizedBox(
width: 56,
child: Text(label,
style: const TextStyle(
fontSize: 13, color: AppTheme.textSecondary))),
style: TextStyle(
fontSize: 13, color: context.tokens.muted))),
const SizedBox(width: 8),
Expanded(
child: Text(value, style: const TextStyle(fontSize: 13))),
@@ -361,7 +361,7 @@ class _ProductDetailScreenState extends ConsumerState<ProductDetailScreen> {
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6),
side: BorderSide(color: AppTheme.border, width: 0.5),
side: BorderSide(color: context.tokens.border, width: 0.5),
),
child: Padding(
padding: const EdgeInsets.all(16),
@@ -412,7 +412,7 @@ class _ProductDetailScreenState extends ConsumerState<ProductDetailScreen> {
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6),
side: BorderSide(color: AppTheme.border, width: 0.5),
side: BorderSide(color: context.tokens.border, width: 0.5),
),
child: Padding(
padding: const EdgeInsets.all(16),
@@ -425,8 +425,8 @@ class _ProductDetailScreenState extends ConsumerState<ProductDetailScreen> {
if (p.descriptionDocContent?.isNotEmpty ?? false) ...[
const SizedBox(height: 10),
Text(p.descriptionDocContent!,
style: const TextStyle(
fontSize: 13, color: AppTheme.textSecondary, height: 1.6)),
style: TextStyle(
fontSize: 13, color: context.tokens.muted, height: 1.6)),
],
],
),
@@ -443,20 +443,20 @@ class _ProductDetailScreenState extends ConsumerState<ProductDetailScreen> {
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6),
side: BorderSide(color: AppTheme.border, width: 0.5),
side: BorderSide(color: context.tokens.border, width: 0.5),
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
child: Row(
children: [
const Text('建议零售价',
style: TextStyle(fontSize: 13, color: AppTheme.textSecondary)),
Text('建议零售价',
style: TextStyle(fontSize: 13, color: context.tokens.muted)),
const Spacer(),
Text('¥$priceStr',
style: const TextStyle(
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.w700,
color: AppTheme.danger)),
color: context.tokens.danger)),
],
),
),
@@ -468,7 +468,7 @@ class _ProductDetailScreenState extends ConsumerState<ProductDetailScreen> {
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6),
side: BorderSide(color: AppTheme.border, width: 0.5),
side: BorderSide(color: context.tokens.border, width: 0.5),
),
child: Padding(
padding: const EdgeInsets.all(16),
@@ -509,14 +509,14 @@ class _ProductDetailScreenState extends ConsumerState<ProductDetailScreen> {
minLines: 3,
decoration: InputDecoration(
hintText: '输入商品描述,例如酒的产地、工艺、口感等...',
hintStyle: const TextStyle(
fontSize: 13, color: AppTheme.textSecondary),
hintStyle: TextStyle(
fontSize: 13, color: context.tokens.muted),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(4),
borderSide: BorderSide(color: AppTheme.border)),
borderSide: BorderSide(color: context.tokens.border)),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(4),
borderSide: BorderSide(color: AppTheme.border)),
borderSide: BorderSide(color: context.tokens.border)),
contentPadding: const EdgeInsets.all(12),
),
),
@@ -532,7 +532,7 @@ class _ProductDetailScreenState extends ConsumerState<ProductDetailScreen> {
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6),
side: BorderSide(color: AppTheme.border, width: 0.5),
side: BorderSide(color: context.tokens.border, width: 0.5),
),
child: Padding(
padding: const EdgeInsets.all(16),
@@ -547,9 +547,9 @@ class _ProductDetailScreenState extends ConsumerState<ProductDetailScreen> {
children: [
Expanded(
child: Text(publicUrl,
style: const TextStyle(
style: TextStyle(
fontSize: 12,
color: AppTheme.primary,
color: context.tokens.primary,
fontFamily: 'monospace')),
),
const SizedBox(width: 8),
@@ -597,9 +597,9 @@ class _ImageThumbnail extends StatelessWidget {
errorBuilder: (_, __, ___) => Container(
width: 110,
height: 110,
color: AppTheme.border,
child: const Icon(Icons.broken_image,
color: AppTheme.textSecondary),
color: context.tokens.border,
child: Icon(Icons.broken_image,
color: context.tokens.muted),
),
),
),
@@ -642,9 +642,9 @@ class _UploadButton extends StatelessWidget {
width: 110,
height: 110,
decoration: BoxDecoration(
border: Border.all(color: AppTheme.border, width: 1.5),
border: Border.all(color: context.tokens.border, width: 1.5),
borderRadius: BorderRadius.circular(4),
color: AppTheme.background,
color: context.tokens.bg,
),
child: uploading
? const Center(
@@ -652,15 +652,15 @@ class _UploadButton extends StatelessWidget {
width: 24,
height: 24,
child: CircularProgressIndicator(strokeWidth: 2)))
: const Column(
: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.add_photo_alternate_outlined,
size: 28, color: AppTheme.textSecondary),
SizedBox(height: 4),
size: 28, color: context.tokens.muted),
const SizedBox(height: 4),
Text('上传图片',
style: TextStyle(
fontSize: 11, color: AppTheme.textSecondary)),
fontSize: 11, color: context.tokens.muted)),
],
),
),
@@ -2,7 +2,7 @@ import '../../core/utils/dialog_util.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../core/responsive/responsive.dart';
import '../../core/theme/app_theme.dart';
import '../../core/theme/context_tokens.dart';
import '../../models/warehouse.dart';
import '../../providers/product_option_provider.dart';
import '../../providers/warehouse_provider.dart';
@@ -174,8 +174,8 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
? [
DataRow(cells: [
const DataCell(SizedBox()),
const DataCell(Text('暂无数据',
style: TextStyle(color: AppTheme.textSecondary))),
DataCell(Text('暂无数据',
style: TextStyle(color: context.tokens.muted))),
const DataCell(SizedBox()),
const DataCell(SizedBox()),
])
@@ -183,10 +183,10 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
: paged
.map((it) => DataRow(cells: [
DataCell(Text(it.code ?? '-',
style: const TextStyle(
style: TextStyle(
fontFamily: 'monospace',
fontSize: 12,
color: AppTheme.textSecondary))),
color: context.tokens.muted))),
DataCell(Text(it.name,
style:
const TextStyle(fontWeight: FontWeight.w500))),
@@ -309,8 +309,8 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
? [
DataRow(cells: [
const DataCell(SizedBox()),
const DataCell(Text('暂无数据',
style: TextStyle(color: AppTheme.textSecondary))),
DataCell(Text('暂无数据',
style: TextStyle(color: context.tokens.muted))),
const DataCell(SizedBox()),
const DataCell(SizedBox()),
])
@@ -318,10 +318,10 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
: paged
.map((it) => DataRow(cells: [
DataCell(Text(it.code ?? '-',
style: const TextStyle(
style: TextStyle(
fontFamily: 'monospace',
fontSize: 12,
color: AppTheme.textSecondary))),
color: context.tokens.muted))),
DataCell(Text(it.name,
style:
const TextStyle(fontWeight: FontWeight.w500))),
@@ -448,8 +448,8 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
? [
DataRow(cells: [
const DataCell(SizedBox()),
const DataCell(Text('暂无数据',
style: TextStyle(color: AppTheme.textSecondary))),
DataCell(Text('暂无数据',
style: TextStyle(color: context.tokens.muted))),
const DataCell(SizedBox()),
const DataCell(SizedBox()),
const DataCell(SizedBox()),
@@ -458,10 +458,10 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
: paged
.map((it) => DataRow(cells: [
DataCell(Text(it.code ?? '-',
style: const TextStyle(
style: TextStyle(
fontFamily: 'monospace',
fontSize: 12,
color: AppTheme.textSecondary))),
color: context.tokens.muted))),
DataCell(Text(it.name,
style:
const TextStyle(fontWeight: FontWeight.w500))),
@@ -547,10 +547,10 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
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: onRetry, child: const Text('重试')),
],
@@ -608,8 +608,8 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
WriteGuard(
child: TextButton(
onPressed: onDelete,
child: const Text('删除',
style: TextStyle(fontSize: 13, color: AppTheme.danger)),
child: Text('删除',
style: TextStyle(fontSize: 13, color: context.tokens.danger)),
),
),
],
@@ -635,7 +635,7 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
size: 20,
color: isDefault
? const Color(0xFFFFB300) // 明亮金色,醒目区分默认项
: AppTheme.textSecondary),
: context.tokens.muted),
onPressed: isDefault ? null : onSetDefault,
),
TextButton(
@@ -644,8 +644,8 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
),
TextButton(
onPressed: onDelete,
child: const Text('删除',
style: TextStyle(fontSize: 12, color: AppTheme.danger)),
child: Text('删除',
style: TextStyle(fontSize: 12, color: context.tokens.danger)),
),
],
),
@@ -707,7 +707,7 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
ElevatedButton(
onPressed: () => Navigator.of(ctx).pop(true),
style: ElevatedButton.styleFrom(
backgroundColor: AppTheme.danger,
backgroundColor: context.tokens.danger,
foregroundColor: Colors.white),
child: const Text('删除'),
),
@@ -721,7 +721,7 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('删除失败:$e'), backgroundColor: AppTheme.danger),
content: Text('删除失败:$e'), backgroundColor: context.tokens.danger),
);
}
}
@@ -810,8 +810,8 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
? [
DataRow(cells: [
const DataCell(SizedBox()),
const DataCell(Text('暂无数据',
style: TextStyle(color: AppTheme.textSecondary))),
DataCell(Text('暂无数据',
style: TextStyle(color: context.tokens.muted))),
const DataCell(SizedBox()),
const DataCell(SizedBox())
])
@@ -819,10 +819,10 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
: paged
.map((it) => DataRow(cells: [
DataCell(Text(it.code ?? '-',
style: const TextStyle(
style: TextStyle(
fontFamily: 'monospace',
fontSize: 12,
color: AppTheme.textSecondary))),
color: context.tokens.muted))),
DataCell(Text(it.name,
style:
const TextStyle(fontWeight: FontWeight.w500))),
@@ -935,8 +935,8 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
? [
DataRow(cells: [
const DataCell(SizedBox()),
const DataCell(Text('暂无数据',
style: TextStyle(color: AppTheme.textSecondary))),
DataCell(Text('暂无数据',
style: TextStyle(color: context.tokens.muted))),
const DataCell(SizedBox()),
const DataCell(SizedBox())
])
@@ -944,10 +944,10 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
: paged
.map((it) => DataRow(cells: [
DataCell(Text(it.code ?? '-',
style: const TextStyle(
style: TextStyle(
fontFamily: 'monospace',
fontSize: 12,
color: AppTheme.textSecondary))),
color: context.tokens.muted))),
DataCell(Text(it.name,
style:
const TextStyle(fontWeight: FontWeight.w500))),
@@ -1060,8 +1060,8 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
? [
DataRow(cells: [
const DataCell(SizedBox()),
const DataCell(Text('暂无数据',
style: TextStyle(color: AppTheme.textSecondary))),
DataCell(Text('暂无数据',
style: TextStyle(color: context.tokens.muted))),
const DataCell(SizedBox()),
const DataCell(SizedBox())
])
@@ -1069,10 +1069,10 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
: paged
.map((it) => DataRow(cells: [
DataCell(Text(it.code ?? '-',
style: const TextStyle(
style: TextStyle(
fontFamily: 'monospace',
fontSize: 12,
color: AppTheme.textSecondary))),
color: context.tokens.muted))),
DataCell(Text(it.name,
style:
const TextStyle(fontWeight: FontWeight.w500))),
@@ -1180,9 +1180,9 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
.read(
productDescriptionDocListProvider.notifier)
.delete(it.id)),
child: const Text('删除',
child: Text('删除',
style: TextStyle(
fontSize: 13, color: AppTheme.danger)),
fontSize: 13, color: context.tokens.danger)),
),
],
))
@@ -1197,8 +1197,8 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
? [
DataRow(cells: [
const DataCell(SizedBox()),
const DataCell(Text('暂无数据',
style: TextStyle(color: AppTheme.textSecondary))),
DataCell(Text('暂无数据',
style: TextStyle(color: context.tokens.muted))),
const DataCell(SizedBox()),
const DataCell(SizedBox())
])
@@ -1211,8 +1211,8 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
DataCell(Text(it.title,
style: const TextStyle(fontWeight: FontWeight.w500))),
DataCell(Text(preview,
style: const TextStyle(
fontSize: 12, color: AppTheme.textSecondary))),
style: TextStyle(
fontSize: 12, color: context.tokens.muted))),
DataCell(Text(it.remark ?? '-')),
DataCell(_actionButtons(
onEdit: () => _showDescDocDialog(
@@ -1308,7 +1308,7 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('保存失败:$e'),
backgroundColor: AppTheme.danger),
backgroundColor: context.tokens.danger),
);
}
}
@@ -1358,9 +1358,9 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
),
TextButton(
onPressed: () => _confirmDeleteWarehouse(w),
child: const Text('删除',
style:
TextStyle(fontSize: 13, color: AppTheme.danger)),
child: Text('删除',
style: TextStyle(
fontSize: 13, color: context.tokens.danger)),
),
],
))
@@ -1373,12 +1373,12 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
],
rows: warehouses.isEmpty
? [
const DataRow(cells: [
DataCell(SizedBox()),
DataRow(cells: [
const DataCell(SizedBox()),
DataCell(Text('暂无仓库',
style: TextStyle(color: AppTheme.textSecondary))),
DataCell(SizedBox()),
DataCell(SizedBox()),
style: TextStyle(color: context.tokens.muted))),
const DataCell(SizedBox()),
const DataCell(SizedBox()),
])
]
: warehouses
@@ -1387,8 +1387,8 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
style: const TextStyle(fontWeight: FontWeight.w500))),
DataCell(Text(w.location ?? '-')),
DataCell(w.isDefault
? const Icon(Icons.check_circle,
color: AppTheme.success, size: 18)
? Icon(Icons.check_circle,
color: context.tokens.success, size: 18)
: const SizedBox()),
DataCell(_actionButtons(
onEdit: () => _showWarehouseDialog(warehouse: w),
@@ -1423,7 +1423,7 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
ElevatedButton(
onPressed: () => Navigator.of(ctx).pop(true),
style: ElevatedButton.styleFrom(
backgroundColor: AppTheme.danger,
backgroundColor: context.tokens.danger,
foregroundColor: Colors.white),
child: const Text('删除'),
),
@@ -1434,13 +1434,15 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
try {
await ref.read(warehouseListProvider.notifier).deleteWarehouse(w.id);
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('删除成功'), backgroundColor: AppTheme.success));
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: const Text('删除成功'),
backgroundColor: context.tokens.success));
}
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('删除失败:$e'), backgroundColor: AppTheme.danger));
content: Text('删除失败:$e'),
backgroundColor: context.tokens.danger));
}
}
}
@@ -1527,7 +1529,7 @@ class _ProductsScreenState extends ConsumerState<ProductsScreen> {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('创建失败:$e'),
backgroundColor: AppTheme.danger),
backgroundColor: context.tokens.danger),
);
}
}
@@ -1595,13 +1597,14 @@ class _WarehouseFormDialogState extends ConsumerState<_WarehouseFormDialog> {
widget.onSaved();
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(widget.warehouse != null ? '仓库更新成功' : '仓库创建成功'),
backgroundColor: AppTheme.success,
backgroundColor: context.tokens.success,
));
}
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('保存失败:$e'), backgroundColor: AppTheme.danger));
content: Text('保存失败:$e'),
backgroundColor: context.tokens.danger));
}
} finally {
if (mounted) setState(() => _saving = false);