- 将 AddItemScreen 中的各个字段提取为独立的 Widget - 新增 CategoryDropdown、DatePickerField、DescriptionField 等组件 - 优化 Item 模型,使用 ItemIsUse 枚举替代字符串表示是否使用 - 在数据库中添加 price 字段- 重构表单提交逻辑,使用新的组件进行数据采集
29 lines
718 B
Dart
29 lines
718 B
Dart
import 'package:flutter/material.dart';
|
|
|
|
class NameInputField extends StatelessWidget {
|
|
final String initialValue;
|
|
final ValueChanged<String> onChanged;
|
|
|
|
const NameInputField({required this.initialValue, required this.onChanged});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return TextFormField(
|
|
initialValue: initialValue,
|
|
onChanged: onChanged,
|
|
decoration: InputDecoration(
|
|
labelText: '名称',
|
|
hintText: '请输入名称',
|
|
border: OutlineInputBorder(),
|
|
),
|
|
maxLength: 20,
|
|
validator: (value) {
|
|
if (value == null || value.trim().isEmpty) {
|
|
return '名称不能为空';
|
|
}
|
|
return null;
|
|
},
|
|
);
|
|
}
|
|
}
|