66 lines
1.8 KiB
Dart
66 lines
1.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../../providers/health_provider.dart';
|
|
|
|
/// 首页仪表盘上「强宝健康」卡片的摘要:当前体重 + 今日热量。
|
|
///
|
|
/// 只是两个数字,所以单独取 —— 不复用主页那套 provider(那些会拉明细),
|
|
/// 为了一行字把整天饮食记录取回来是不划算的。
|
|
class HealthModuleSummary extends ConsumerWidget {
|
|
const HealthModuleSummary({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final goal = ref.watch(weightGoalProvider).value;
|
|
final totals = ref.watch(dietTodayTotalsProvider).value;
|
|
|
|
final weight = goal?.currentWeight;
|
|
|
|
return Row(
|
|
children: [
|
|
Expanded(
|
|
child: _item(
|
|
'当前体重',
|
|
weight == null ? null : '${_fmt(weight)} kg',
|
|
),
|
|
),
|
|
Expanded(
|
|
child: _item(
|
|
'今日热量',
|
|
totals == null || totals.itemCount == 0
|
|
? null
|
|
: '${_fmt(totals.energyKcal)} kcal',
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _item(String label, String? value) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(label,
|
|
style: const TextStyle(fontSize: 11, color: Color(0xFF8D6E63))),
|
|
const SizedBox(height: 3),
|
|
Text(
|
|
value ?? '--',
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: const TextStyle(
|
|
fontSize: 14.5,
|
|
fontWeight: FontWeight.bold,
|
|
color: Color(0xFF5D4037),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
String _fmt(num value) {
|
|
if (value == value.roundToDouble()) return value.round().toString();
|
|
return value.toStringAsFixed(1);
|
|
}
|