This commit is contained in:
JMARyA 2024-09-05 10:25:18 +02:00
parent fba5d1ae87
commit fb1677ed73
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
2 changed files with 43 additions and 17 deletions

View file

@ -47,8 +47,20 @@ class API {
jsonDecode(await getRequest("$instance/transaction/$id")));
}
Future<List<Map<String, dynamic>>> getInventory(String item) async {
return jsonDecode(await getRequest("$instance/item/$item/inventory"));
Future<List<Transaction>> getInventory(String item) async {
var resp = jsonDecode(await getRequest("$instance/item/$item/inventory"))
as List<dynamic>;
return resp.map((x) => Transaction(x)).toList();
}
Future<List<Transaction>> getInventoryOfVariant(
String item, String variant) async {
var resp =
jsonDecode(await getRequest("$instance/item/$item/$variant/inventory"))
as List<dynamic>;
return resp.map((x) => Transaction(x)).toList();
}
Future<String> supplyItem(String item, String variant, String price,

View file

@ -26,26 +26,21 @@ class ItemView extends StatelessWidget {
],
),
const SizedBox(height: 10),
Row(
children: item.variants.entries.map((entry) {
return Text(entry.value.name);
}).toList()),
FutureBuilder(
future: API().getInventory(item.id),
builder: (context, snapshot) {
if (snapshot.hasData) {
var data = snapshot.data!;
return Column(
children: data.map((x) {
return Row(
children: [
Text(x["uuid"]),
Text(x["origin"]),
Text(x["price"]),
Text(x["timestamp"])
],
);
}).toList());
if (!snapshot.hasData) {
return const CircularProgressIndicator();
}
var data = snapshot.data!;
return const CircularProgressIndicator();
return Expanded(
child: ListView(
children: data.map((x) => TransactionCard(x)).toList()));
},
)
]),
@ -61,6 +56,25 @@ class ItemView extends StatelessWidget {
const ItemView({super.key, required this.item});
}
class TransactionCard extends StatelessWidget {
final Transaction t;
const TransactionCard(this.t, {super.key});
@override
Widget build(BuildContext context) {
return Card(
child: Column(
children: [
Row(
children: [Text(t.uuid), Text(t.item), Text(t.variant)],
),
],
),
);
}
}
class SupplyPage extends StatefulWidget {
final Item item;