flutter-demo/lib/screens/item_screens/widgets/price_input_field.dart
LingandRX faf439087a refactor(item): 重构添加物品页面
- 将 AddItemScreen 中的各个字段提取为独立的 Widget
- 新增 CategoryDropdown、DatePickerField、DescriptionField 等组件
- 优化 Item 模型,使用 ItemIsUse 枚举替代字符串表示是否使用
- 在数据库中添加 price 字段- 重构表单提交逻辑,使用新的组件进行数据采集
2025-05-06 22:06:19 +08:00

38 lines
975 B
Dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class PriceInputField extends StatelessWidget {
final double? value;
final ValueChanged<double?> onChanged;
const PriceInputField({
Key? key,
required this.value,
required this.onChanged,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final controller = TextEditingController(
text: value != null ? value.toString() : '',
);
return TextField(
controller: controller,
keyboardType: TextInputType.numberWithOptions(decimal: true),
inputFormatters: [
FilteringTextInputFormatter.allow(RegExp(r'^\d*\.?\d{0,2}$')),
],
decoration: InputDecoration(
labelText: "物品价格",
hintText: "请输入物品价格",
border: OutlineInputBorder(),
),
onChanged: (text) {
final parsed = double.tryParse(text);
onChanged(parsed);
},
);
}
}