feat:增加变化提醒功能

This commit is contained in:
2025-12-03 14:28:39 +08:00
parent e672442d6a
commit 8d23f06f74
10 changed files with 194 additions and 68 deletions

View File

@@ -108,6 +108,12 @@ class _RecordDailyState extends State<RecordDaily> {
_buildRecordTitle(type),
const SizedBox(height: 4),
_buildRecordContent(provider.currentRecord, type),
if (checkHasRecordValue(provider.currentRecord, type))
_buildRecordTip(
provider.currentRecord,
provider.selectedDate,
type,
),
],
),
trailing: GestureDetector(
@@ -279,4 +285,49 @@ class _RecordDailyState extends State<RecordDaily> {
return Text(formatContent(record, type), style: TextStyle(fontSize: 14));
}
Widget _buildRecordTip(HealthRecord record, DateTime date, RecordType type) {
late num lastValue = 0;
late String change = '';
switch (type) {
case RecordType.weight:
lastValue = service.getLastWeight(formatDate(date));
break;
case RecordType.sport:
lastValue = service.getLastSport(formatDate(date));
break;
case RecordType.sleep:
lastValue = service.getLastSleep(formatDate(date));
break;
}
if (lastValue == 0) {
return const SizedBox.shrink();
}
switch (type) {
case RecordType.weight:
num difference = record.weight - lastValue;
String formattedDiff = NumberFormat('+0.00;-0.00').format(difference);
change = '较上次 $formattedDiff ${type.unit}';
break;
case RecordType.sport:
num difference = record.sportDuration - lastValue;
String formattedDiff = NumberFormat('+0;-0').format(difference);
change = '较上次 $formattedDiff ${type.unit}';
break;
case RecordType.sleep:
String startTime = record.sleepStartTime;
String endTime = record.sleepEndTime;
num difference = calSleepMinDuration(startTime, endTime) - lastValue;
String formattedDiff = NumberFormat('+0.00;-0.00').format(difference / 60);
change = '较上次 $formattedDiff ${type.unit}';
break;
}
return Text(
change,
style: TextStyle(fontSize: 14, color: Colors.grey[500]),
);
}
}