cdb_ui/lib/pages/items.dart

53 lines
1.3 KiB
Dart
Raw 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});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Items"),
),
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
);
}
}