cdb_ui/lib/pages/items.dart

82 lines
2.2 KiB
Dart
Raw Permalink Normal View History

2024-09-20 07:18:06 +00:00
import 'package:cdb_ui/api.dart';
import 'package:cdb_ui/pages/itemview.dart';
2024-10-08 08:11:18 +00:00
import 'package:cdb_ui/pages/supply.dart';
2024-09-23 08:31:40 +00:00
import 'package:cdb_ui/pages/transaction.dart';
2024-09-20 07:18:06 +00:00
import 'package:flutter/material.dart';
class ItemsPage extends StatelessWidget {
const ItemsPage({super.key});
2024-10-08 08:55:30 +00:00
_scanBarcodeSupply(BuildContext context) async {
var code =
int.parse(await scanQRCode(context, title: "Scan Barcode") ?? "0");
var items = API().getItems();
for (var item in items) {
for (var variant in item.variants.keys) {
for (var barcode in item.variants[variant]!.barcodes ?? []) {
if (code == barcode) {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => SupplyPage(
item,
() {},
onlyVariants: [variant],
)));
}
}
}
}
}
2024-09-20 07:18:06 +00:00
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Items"),
2024-10-08 08:55:30 +00:00
// todo : add barcode scan
actions: [
ElevatedButton(
onPressed: () {
_scanBarcodeSupply(context);
},
child: const Icon(Icons.add_box))
],
2024-09-20 07:18:06 +00:00
),
2024-09-26 19:35:28 +00:00
body: ListView(
children: API().getItems().map((x) {
return ItemTile(x);
}).toList()),
2024-09-23 08:31:40 +00:00
floatingActionButton: FloatingActionButton(
2024-10-08 08:11:18 +00:00
onPressed: () async {
2024-09-23 08:31:40 +00:00
// scan transaction code
2024-10-08 08:11:18 +00:00
var code = await scanQRCode(context, title: "Scan Transaction Code");
2024-09-23 08:31:40 +00:00
2024-10-08 08:11:18 +00:00
API().getTransaction(code!).then((t) {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => TransactionPage(t),
));
});
2024-09-23 08:31:40 +00:00
},
child: const Icon(Icons.qr_code),
),
2024-09-20 07:18:06 +00:00
);
}
}
class ItemTile extends StatelessWidget {
2024-09-21 00:05:45 +00:00
final Item item;
2024-09-20 07:18:06 +00:00
const ItemTile(this.item, {super.key});
@override
Widget build(BuildContext context) {
return ListTile(
onTap: () {
2024-09-21 00:05:45 +00:00
Navigator.push(context,
MaterialPageRoute(builder: (context) => ItemView(item: item)));
2024-09-20 07:18:06 +00:00
},
2024-09-21 00:05:45 +00:00
title: Text(item.name),
2024-09-20 07:18:06 +00:00
);
}
}