feat:更新表单组件

This commit is contained in:
2025-12-09 10:19:50 +08:00
parent adae2bc558
commit 190963f079
12 changed files with 270 additions and 527 deletions

View File

@@ -8,14 +8,25 @@ bool checkHasRecordValue(HealthRecord record, RecordType type) {
case RecordType.sport:
return record.sportDuration != 0;
case RecordType.sleep:
return record.sleepStartTime != '';
return record.sleepStartTime != '' || record.sleepEndTime != '';
}
}
bool checkNeedRecordTip(HealthRecord record, RecordType type) {
switch (type) {
case RecordType.weight:
return record.weight != 0;
case RecordType.sport:
return record.sportDuration != 0;
case RecordType.sleep:
return record.sleepStartTime != '' && record.sleepEndTime != '';
}
}
// 将字符串时间转换为 TimeOfDay
TimeOfDay parseTime(String timeString) {
TimeOfDay? parseTime(String timeString) {
if (timeString.isEmpty) {
return TimeOfDay.now();
return null;
}
try {
final parts = timeString.split(':');
@@ -25,8 +36,23 @@ TimeOfDay parseTime(String timeString) {
}
}
DateTime? timeOfDayToDateTime(TimeOfDay? timeOfDay) {
if (timeOfDay == null) {
return null;
}
final now = DateTime.now();
return DateTime(
now.year,
now.month,
now.day,
timeOfDay.hour,
timeOfDay.minute,
);
}
// 将 TimeOfDay 格式化为字符串 (HH:mm)
String formatTime(TimeOfDay time) {
String formatTime(DateTime time) {
return '${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}';
}
@@ -34,8 +60,8 @@ int calSleepMinDuration(String startTime, String endTime) {
final start = parseTime(startTime);
final end = parseTime(endTime);
int startMinutes = start.hour * 60 + start.minute;
int endMinutes = end.hour * 60 + end.minute;
int startMinutes = start!.hour * 60 + start.minute;
int endMinutes = end!.hour * 60 + end.minute;
// 处理跨天情况(如果结束时间小于开始时间,认为是第二天)
if (endMinutes < startMinutes) {