2024-09-20 07:18:06 +00:00
|
|
|
import 'package:cdb_ui/api.dart';
|
|
|
|
import 'package:cdb_ui/pages/itemview.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';
|
2024-09-23 08:31:40 +00:00
|
|
|
import 'package:qr_bar_code_scanner_dialog/qr_bar_code_scanner_dialog.dart';
|
2024-09-20 07:18:06 +00:00
|
|
|
|
|
|
|
class ItemsPage extends StatelessWidget {
|
|
|
|
const ItemsPage({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: const Text("Items"),
|
|
|
|
),
|
|
|
|
body: FutureBuilder(
|
|
|
|
future: API().getItems(),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (!snapshot.hasData) {
|
|
|
|
return const CircularProgressIndicator();
|
|
|
|
}
|
|
|
|
|
|
|
|
var items = snapshot.data!;
|
|
|
|
|
|
|
|
return ListView(
|
|
|
|
children: items.map((x) {
|
|
|
|
return ItemTile(x);
|
|
|
|
}).toList());
|
|
|
|
}),
|
2024-09-23 08:31:40 +00:00
|
|
|
floatingActionButton: FloatingActionButton(
|
|
|
|
onPressed: () {
|
|
|
|
// scan transaction code
|
|
|
|
QrBarCodeScannerDialog().getScannedQrBarCode(
|
|
|
|
context: context,
|
|
|
|
onCode: (code) {
|
|
|
|
// library is retarded
|
|
|
|
code = code!.replaceFirst("Code scanned = ", "");
|
|
|
|
|
|
|
|
API().getTransaction(code).then((t) {
|
|
|
|
Navigator.of(context).push(MaterialPageRoute(
|
|
|
|
builder: (context) => TransactionPage(t),
|
|
|
|
));
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
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
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|