import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../../../providers/bill_provider.dart'; import '../../../utils/amount_util.dart'; /// 首页仪表盘上「记账」卡片的摘要:当前查看月份的收入 / 支出 / 结余。 /// /// 故意和账单首页共用 `monthAnchorProvider`,而不是自己取 `DateTime.now()`: /// · 两边看到的永远是同一个月,不会出现「卡片写 9 月、点进去是 8 月」 /// · provider 已经是现成的,不会多打一次接口 /// 所以标签用「N月」而不是「本月」。 class BillModuleSummary extends ConsumerWidget { const BillModuleSummary({super.key}); @override Widget build(BuildContext context, WidgetRef ref) { final anchor = ref.watch(monthAnchorProvider); final stats = ref.watch(monthlyStatisticsProvider(anchor)).value; return Row( children: [ Expanded( child: _item('${anchor.month}月支出', stats?.totalExpense, const Color(0xFFFA3534)), ), Expanded( child: _item('结余', stats?.balance, const Color(0xFF5D4037)), ), ], ); } Widget _item(String label, double? amount, Color color) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(label, style: const TextStyle(fontSize: 11, color: Color(0xFF8D6E63))), const SizedBox(height: 3), Text( // 统计还没回来时显示占位,避免卡片高度跳动 amount == null ? '--' : '¥${formatAmount(amount)}', style: TextStyle(fontSize: 14.5, fontWeight: FontWeight.bold, color: color), ), ], ); } }