diff --git a/lib/pages/supply.dart b/lib/pages/supply.dart index 5df8bda..9173f21 100644 --- a/lib/pages/supply.dart +++ b/lib/pages/supply.dart @@ -17,12 +17,13 @@ class _SupplyPageState extends State { final _formKey = GlobalKey(); String _selectedOrigin = ""; String _selectedLocation = ""; - String _price = ""; + late TextEditingController _priceController; @override void initState() { super.initState(); variant = widget.item.variants.keys.first; + _priceController = TextEditingController(text: ""); } void _supply() { @@ -30,8 +31,8 @@ class _SupplyPageState extends State { _formKey.currentState!.save(); API() - .supplyItem(widget.item.name, variant, "$_price €", _selectedOrigin, - _selectedLocation) + .supplyItem(widget.item.name, variant, "${_priceController.text} €", + _selectedOrigin, _selectedLocation) .then((_) { ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('Item added successfully!')), @@ -96,14 +97,14 @@ class _SupplyPageState extends State { _selectedOrigin = value; }, onSelection: (String selection) async { - var price = _price.isEmpty + var price = _priceController.text.isEmpty ? await API() .getLatestPrice(widget.item.id, variant, origin: selection) .then((x) => x.value.toStringAsFixed(2)) - : _price; + : _priceController.text; setState(() { - _price = price; + _priceController.text = price; _selectedOrigin = selection; }); }, @@ -115,7 +116,7 @@ class _SupplyPageState extends State { TextFormField( decoration: const InputDecoration(labelText: 'Price'), keyboardType: TextInputType.number, - initialValue: _price, + controller: _priceController, validator: (value) { if (value == null || value.isEmpty) { return 'Please enter a price'; @@ -125,9 +126,6 @@ class _SupplyPageState extends State { } return null; }, - onSaved: (value) { - _price = value!; - }, ), const SizedBox(height: 16),