cdb_ui/lib/pages/items.dart
2024-10-08 10:11:18 +02:00

52 lines
1.3 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});
@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: () 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),
);
}
}