2024-09-20 07:18:06 +00:00
|
|
|
import 'package:cdb_ui/api.dart';
|
|
|
|
import 'package:cdb_ui/pages/itemview.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: 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());
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|