fix price auto suggest
This commit is contained in:
parent
7b4720f871
commit
35977e9a61
1 changed files with 8 additions and 10 deletions
|
@ -17,12 +17,13 @@ class _SupplyPageState extends State<SupplyPage> {
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
String _selectedOrigin = "";
|
String _selectedOrigin = "";
|
||||||
String _selectedLocation = "";
|
String _selectedLocation = "";
|
||||||
String _price = "";
|
late TextEditingController _priceController;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
variant = widget.item.variants.keys.first;
|
variant = widget.item.variants.keys.first;
|
||||||
|
_priceController = TextEditingController(text: "");
|
||||||
}
|
}
|
||||||
|
|
||||||
void _supply() {
|
void _supply() {
|
||||||
|
@ -30,8 +31,8 @@ class _SupplyPageState extends State<SupplyPage> {
|
||||||
_formKey.currentState!.save();
|
_formKey.currentState!.save();
|
||||||
|
|
||||||
API()
|
API()
|
||||||
.supplyItem(widget.item.name, variant, "$_price €", _selectedOrigin,
|
.supplyItem(widget.item.name, variant, "${_priceController.text} €",
|
||||||
_selectedLocation)
|
_selectedOrigin, _selectedLocation)
|
||||||
.then((_) {
|
.then((_) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
const SnackBar(content: Text('Item added successfully!')),
|
const SnackBar(content: Text('Item added successfully!')),
|
||||||
|
@ -96,14 +97,14 @@ class _SupplyPageState extends State<SupplyPage> {
|
||||||
_selectedOrigin = value;
|
_selectedOrigin = value;
|
||||||
},
|
},
|
||||||
onSelection: (String selection) async {
|
onSelection: (String selection) async {
|
||||||
var price = _price.isEmpty
|
var price = _priceController.text.isEmpty
|
||||||
? await API()
|
? await API()
|
||||||
.getLatestPrice(widget.item.id, variant,
|
.getLatestPrice(widget.item.id, variant,
|
||||||
origin: selection)
|
origin: selection)
|
||||||
.then((x) => x.value.toStringAsFixed(2))
|
.then((x) => x.value.toStringAsFixed(2))
|
||||||
: _price;
|
: _priceController.text;
|
||||||
setState(() {
|
setState(() {
|
||||||
_price = price;
|
_priceController.text = price;
|
||||||
_selectedOrigin = selection;
|
_selectedOrigin = selection;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -115,7 +116,7 @@ class _SupplyPageState extends State<SupplyPage> {
|
||||||
TextFormField(
|
TextFormField(
|
||||||
decoration: const InputDecoration(labelText: 'Price'),
|
decoration: const InputDecoration(labelText: 'Price'),
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
initialValue: _price,
|
controller: _priceController,
|
||||||
validator: (value) {
|
validator: (value) {
|
||||||
if (value == null || value.isEmpty) {
|
if (value == null || value.isEmpty) {
|
||||||
return 'Please enter a price';
|
return 'Please enter a price';
|
||||||
|
@ -125,9 +126,6 @@ class _SupplyPageState extends State<SupplyPage> {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
onSaved: (value) {
|
|
||||||
_price = value!;
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
|
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
|
|
Loading…
Reference in a new issue