81 lines
2.2 KiB
Dart
81 lines
2.2 KiB
Dart
import 'package:cdb_ui/api.dart';
|
|
import 'package:cdb_ui/pages/itemview.dart';
|
|
import 'package:cdb_ui/pages/supply.dart';
|
|
import 'package:cdb_ui/pages/transaction.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class ItemsPage extends StatelessWidget {
|
|
const ItemsPage({super.key});
|
|
|
|
_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],
|
|
)));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text("Items"),
|
|
// todo : add barcode scan
|
|
actions: [
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
_scanBarcodeSupply(context);
|
|
},
|
|
child: const Icon(Icons.add_box))
|
|
],
|
|
),
|
|
body: ListView(
|
|
children: API().getItems().map((x) {
|
|
return ItemTile(x);
|
|
}).toList()),
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: () async {
|
|
// scan transaction code
|
|
var code = await scanQRCode(context, title: "Scan Transaction Code");
|
|
|
|
API().getTransaction(code!).then((t) {
|
|
Navigator.of(context).push(MaterialPageRoute(
|
|
builder: (context) => TransactionPage(t),
|
|
));
|
|
});
|
|
},
|
|
child: const Icon(Icons.qr_code),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class ItemTile extends StatelessWidget {
|
|
final Item item;
|
|
|
|
const ItemTile(this.item, {super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ListTile(
|
|
onTap: () {
|
|
Navigator.push(context,
|
|
MaterialPageRoute(builder: (context) => ItemView(item: item)));
|
|
},
|
|
title: Text(item.name),
|
|
);
|
|
}
|
|
}
|