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

@@ -108,7 +108,8 @@ class _RecordDailyState extends State<RecordDaily> {
_buildRecordTitle(type),
const SizedBox(height: 4),
_buildRecordContent(provider.currentRecord, type),
if (checkHasRecordValue(provider.currentRecord, type))
const SizedBox(height: 4),
if (checkNeedRecordTip(provider.currentRecord, type))
_buildRecordTip(
provider.currentRecord,
provider.selectedDate,

View File

@@ -3,9 +3,7 @@ import 'package:fitnote/models/health.dart';
import 'package:fitnote/provider/health_provider.dart';
import 'package:fitnote/service/health_service.dart';
import 'package:fitnote/utils/record_utils.dart';
import 'package:fitnote/widget/dropdown_select.dart';
import 'package:fitnote/widget/number_input.dart';
import 'package:fitnote/widget/time_picker.dart';
import 'package:fitnote/widget/form.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
@@ -79,22 +77,18 @@ class _RecordFormState extends State<RecordForm> {
children: [
_buildFormTitle('记录体重'),
SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_buildFiledTitle('体重:'),
SizedBox(width: 10),
NumberInput(
value: provider.formItem.weight,
min: 0,
max: 100,
step: 0.1,
unit: 'Kg',
onChanged: (value) => provider.updateWeight(value!),
),
],
buildFormSlider(
context: context,
name: 'slider',
title: '体重Kg',
label: provider.formItem.weight.toString(),
min: 70,
max: 75,
initialValue: 72,
divisions: 50,
onChanged: (value) => provider.updateWeight(value!),
),
SizedBox(height: 20),
SizedBox(height: 10),
],
);
case RecordType.sport:
@@ -103,81 +97,66 @@ class _RecordFormState extends State<RecordForm> {
children: [
_buildFormTitle('记录运动'),
SizedBox(height: 24),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_buildFiledTitle('运动类型:'),
SizedBox(width: 10),
DropdownSelect(
value: provider.formItem.sportProject,
items: AppConfig.sportProjectList,
onChanged: (value) => provider.updateSportProject(value!),
),
],
buildFormRadioGroup(
context: context,
title: '运动类型',
name: 'sport',
initialValue: provider.formItem.sportProject,
items: AppConfig.sportProjectList,
onChanged: (value) => provider.updateSportProject(value!),
),
SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_buildFiledTitle('运动时长:'),
SizedBox(width: 10),
NumberInput(
value: provider.formItem.sportDuration,
min: 5,
max: 240,
step: 5,
unit: '分钟',
onChanged: (value) => provider.updateSportDuration(value!),
),
],
SizedBox(height: 10),
buildFormSlider(
context: context,
name: 'slider',
title: '时长(分钟)',
label: provider.formItem.sportDuration.toString(),
min: 0,
max: 120,
initialValue: 30,
divisions: 12,
onChanged: (value) => provider.updateSportDuration(value!),
),
SizedBox(height: 24),
SizedBox(height: 10),
],
);
case RecordType.sleep:
final startTime = provider.formItem.sleepStartTime;
final endTime = provider.formItem.sleepEndTime;
return Column(
mainAxisSize: MainAxisSize.min,
children: [
_buildFormTitle('记录睡眠'),
SizedBox(height: 24),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_buildFiledTitle('入睡时间'),
SizedBox(width: 10),
TimePicker(
initialTime: parseTime(provider.formItem.sleepStartTime),
label: provider.formItem.sleepStartTime,
onTimeSelected: (time) {
provider.updateSleepStartTime(formatTime(time));
final startTime = provider.formItem.sleepStartTime;
final endTime = provider.formItem.sleepEndTime;
calSleepDuration(startTime, endTime);
},
),
],
buildFormTime(
context: context,
name: 'startTime',
title: '入睡时间',
initialValue: timeOfDayToDateTime(parseTime(startTime)),
onChanged: (time) {
provider.updateSleepStartTime(formatTime(time!));
final startTime = provider.formItem.sleepStartTime;
final endTime = provider.formItem.sleepEndTime;
calSleepDuration(startTime, endTime);
},
),
SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_buildFiledTitle('起床时间'),
SizedBox(width: 10),
TimePicker(
initialTime: parseTime(provider.formItem.sleepEndTime),
label: provider.formItem.sleepEndTime,
onTimeSelected: (time) {
provider.updateSleepEndTime(formatTime(time));
final startTime = provider.formItem.sleepStartTime;
final endTime = provider.formItem.sleepEndTime;
calSleepDuration(startTime, endTime);
},
),
],
SizedBox(height: 10),
buildFormTime(
context: context,
name: 'endTime',
title: '起床时间',
initialValue: timeOfDayToDateTime(parseTime(endTime)),
onChanged: (time) {
provider.updateSleepEndTime(formatTime(time!));
final startTime = provider.formItem.sleepStartTime;
final endTime = provider.formItem.sleepEndTime;
calSleepDuration(startTime, endTime);
},
),
SizedBox(height: 20),
SizedBox(height: 10),
_buildSleepDuration(provider.formItem),
SizedBox(height: 24),
SizedBox(height: 10),
],
);
}