feat:增加删除功能

This commit is contained in:
2025-12-03 19:55:34 +08:00
parent 8d23f06f74
commit adae2bc558
3 changed files with 70 additions and 7 deletions

View File

@@ -167,7 +167,7 @@ class _RecordDailyState extends State<RecordDaily> {
} else {
switch (provider.type) {
case RecordType.weight:
provider.updateWeight(70);
provider.updateWeight(AppConfig.initWeight);
break;
case RecordType.sport:
provider.updateSportProject(AppConfig.sportProjectList[0]);
@@ -189,13 +189,13 @@ class _RecordDailyState extends State<RecordDaily> {
padding: EdgeInsets.all(20),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [RecordForm(type: type), _buildDialogButton()],
children: [RecordForm(type: type), _buildDialogButton(type)],
),
),
);
}
Widget _buildDialogButton() {
Widget _buildDialogButton(RecordType type) {
final colors = Theme.of(context).colorScheme;
return Row(
@@ -211,6 +211,17 @@ class _RecordDailyState extends State<RecordDaily> {
),
),
const SizedBox(width: 12),
Expanded(
child: GFButton(
onPressed: () {
Navigator.of(context).pop();
_deleteRecord(type);
},
color: Colors.red,
text: "删除",
),
),
const SizedBox(width: 12),
Expanded(
child: GFButton(
onPressed: () {
@@ -244,6 +255,25 @@ class _RecordDailyState extends State<RecordDaily> {
}
}
void _deleteRecord(RecordType type) async{
final provider = context.read<HealthProvider>();
switch(type) {
case RecordType.weight:
provider.updateWeight(0);
break;
case RecordType.sport:
provider.updateSportDuration(0);
break;
case RecordType.sleep:
provider.updateSleepStartTime('');
provider.updateSleepEndTime('');
break;
}
_saveRecord();
}
void _saveRecord() async {
final provider = context.read<HealthProvider>();