add latest price autocomplete

This commit is contained in:
JMARyA 2024-09-16 08:35:13 +02:00
parent 5f5487803b
commit 370a5329a9
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
2 changed files with 17 additions and 1 deletions

View file

@ -184,6 +184,19 @@ class API {
return resp.map((x) => Price(x)).toList();
}
Future<Price> getLatestPrice(String item, String variant,
{String? origin}) async {
var url = "$instance/item/$item/$variant/price_latest";
if (origin != null) {
url += "?origin=$origin";
}
var resp = jsonDecode(await getRequest(url)) as Map<String, dynamic>;
return Price(resp);
}
// Flows
// /flows

View file

@ -98,8 +98,11 @@ class _SupplyPageState extends State<SupplyPage> {
.contains(textEditingValue.text.toLowerCase());
});
},
onSelected: (String selection) {
onSelected: (String selection) async {
var price =
await API().getLatestPrice(widget.item.id, variant);
setState(() {
_price = price.value.toStringAsFixed(2);
_selectedOrigin = selection;
});
},