- 将 AddItemScreen 中的各个字段提取为独立的 Widget - 新增 CategoryDropdown、DatePickerField、DescriptionField 等组件 - 优化 Item 模型,使用 ItemIsUse 枚举替代字符串表示是否使用 - 在数据库中添加 price 字段- 重构表单提交逻辑,使用新的组件进行数据采集
46 lines
1.4 KiB
Dart
46 lines
1.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
class DatePickerField extends StatelessWidget {
|
|
final DateTime? selectedDate;
|
|
final ValueChanged<DateTime?> onDateSelected;
|
|
const DatePickerField({
|
|
required this.selectedDate,
|
|
required this.onDateSelected,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
selectedDate == null
|
|
? '请选择日期'
|
|
: '已选择日期: ${selectedDate!.year}年${selectedDate!.month}月${selectedDate!.day}日',
|
|
),
|
|
SizedBox(height: 8),
|
|
ElevatedButton.icon(
|
|
icon: Icon(Icons.calendar_today, color: Colors.white),
|
|
label: Text('选择日期'),
|
|
onPressed: () async {
|
|
final pickedDate = await showDatePicker(
|
|
context: context,
|
|
initialEntryMode: DatePickerEntryMode.calendarOnly,
|
|
initialDate: DateTime.now(),
|
|
firstDate: DateTime(2015, 8),
|
|
lastDate: DateTime(2101),
|
|
);
|
|
if (pickedDate == null) {
|
|
return;
|
|
}
|
|
onDateSelected(pickedDate);
|
|
},
|
|
style: ElevatedButton.styleFrom(
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|