import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; class PriceInputField extends StatelessWidget { final double? value; final ValueChanged 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); }, ); } }