feat:更新UI布局

This commit is contained in:
2025-12-03 11:49:50 +08:00
parent e2853483f7
commit e672442d6a
9 changed files with 196 additions and 189 deletions

View File

@@ -1,3 +1,4 @@
import 'package:fitnote/config/app_config.dart';
import 'package:fitnote/models/health.dart';
import 'package:fitnote/provider/health_provider.dart';
import 'package:fitnote/service/health_service.dart';
@@ -21,7 +22,7 @@ class RecordDaily extends StatefulWidget {
class _RecordDailyState extends State<RecordDaily> {
final HealthService service = HealthService();
@override
Widget build(BuildContext context) {
return CommonCard(
@@ -61,16 +62,12 @@ class _RecordDailyState extends State<RecordDaily> {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
decoration: BoxDecoration(
color: const Color(0xFFF1F5F9),
color: Colors.grey.shade100,
borderRadius: BorderRadius.circular(16),
),
child: Text(
DateFormat('MM月dd日').format(provider.selectedDate),
style: const TextStyle(
fontSize: 12,
color: Color(0xFF64748B),
fontWeight: FontWeight.w500,
),
style: const TextStyle(fontSize: 12),
),
);
}
@@ -108,14 +105,7 @@ class _RecordDailyState extends State<RecordDaily> {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
type.title,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: type.color,
),
),
_buildRecordTitle(type),
const SizedBox(height: 4),
_buildRecordContent(provider.currentRecord, type),
],
@@ -174,7 +164,7 @@ class _RecordDailyState extends State<RecordDaily> {
provider.updateWeight(70);
break;
case RecordType.sport:
provider.updateSportProject('跑步');
provider.updateSportProject(AppConfig.sportProjectList[0]);
provider.updateSportDuration(30);
break;
case RecordType.sleep:
@@ -184,18 +174,18 @@ class _RecordDailyState extends State<RecordDaily> {
}
}
showDialog(
context: context,
builder:
(context) => Dialog(
child: Padding(
padding: EdgeInsets.all(20),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [RecordForm(type: type), _buildDialogButton()],
),
),
),
showDialog(context: context, builder: (context) => _buildDialog(type));
}
Widget _buildDialog(RecordType type) {
return Dialog(
child: Padding(
padding: EdgeInsets.all(20),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [RecordForm(type: type), _buildDialogButton()],
),
),
);
}
@@ -210,7 +200,7 @@ class _RecordDailyState extends State<RecordDaily> {
Navigator.of(context).pop();
_resetRecord();
},
color: colors.secondary,
color: Colors.grey,
text: "取消",
),
),
@@ -250,7 +240,7 @@ class _RecordDailyState extends State<RecordDaily> {
void _saveRecord() async {
final provider = context.read<HealthProvider>();
final newRecord = HealthRecord(
date: formatDate(provider.selectedDate),
weight: provider.formItem.weight,
@@ -261,48 +251,32 @@ class _RecordDailyState extends State<RecordDaily> {
);
await service.updateRecord(newRecord);
provider.updateRecord(service.getRecordByDate(provider.selectedDate));
_refreshGoalProcess(provider);
}
void _refreshGoalProcess(HealthProvider provider) {
provider.updateLatestWeight(service.getLatestWeight());
provider.updateTotalSpot(service.getTotalSport());
provider.updateAvgSleep(service.getAvgSleep());
}
Widget _buildRecordTitle(RecordType type) {
return Text(
type.title,
style: TextStyle(fontWeight: FontWeight.bold, color: type.color),
);
}
Widget _buildRecordContent(HealthRecord record, RecordType type) {
if (!checkHasRecordValue(record, type)) {
return Text(
"尚未记录今日数据,点击添加",
style: TextStyle(fontSize: 12, color: Colors.grey[500]),
style: TextStyle(fontSize: 14, color: Colors.grey[500]),
);
}
late String title;
switch (type) {
case RecordType.weight:
title = "${record.weight} kg";
case RecordType.sport:
title = "${record.sportProject} · ${record.sportDuration}分钟";
case RecordType.sleep:
final startTime = record.sleepStartTime;
final endTime = record.sleepEndTime;
if (startTime.isNotEmpty && endTime.isNotEmpty) {
final duration = calSleepDuration(startTime, endTime);
title = "入睡 $startTime · 起床 $endTime · ${duration}";
} else if (startTime.isNotEmpty) {
title = "入睡 $startTime";
} else if (endTime.isNotEmpty) {
title = "起床 $endTime";
}
}
return Text(
title,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Colors.grey[800],
),
);
return Text(formatContent(record, type), style: TextStyle(fontSize: 14));
}
}