diff --git a/lib/api.dart b/lib/api.dart index 8c4c05f..19abb1f 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -184,6 +184,19 @@ class API { return resp.map((x) => Price(x)).toList(); } + Future 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; + + return Price(resp); + } + // Flows // /flows diff --git a/lib/pages/supply.dart b/lib/pages/supply.dart index aa254c0..89b3b74 100644 --- a/lib/pages/supply.dart +++ b/lib/pages/supply.dart @@ -98,8 +98,11 @@ class _SupplyPageState extends State { .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; }); },