cdb_ui/lib/pages/items.dart
2024-09-26 21:35:28 +02:00

58 lines
1.5 KiB
Dart

import 'package:cdb_ui/api.dart';
import 'package:cdb_ui/pages/itemview.dart';
import 'package:cdb_ui/pages/transaction.dart';
import 'package:flutter/material.dart';
import 'package:qr_bar_code_scanner_dialog/qr_bar_code_scanner_dialog.dart';
class ItemsPage extends StatelessWidget {
const ItemsPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Items"),
),
body: ListView(
children: API().getItems().map((x) {
return ItemTile(x);
}).toList()),
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),
),
);
}
}
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),
);
}
}