48 lines
1.1 KiB
Dart
48 lines
1.1 KiB
Dart
|
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 {
|
||
|
final String item;
|
||
|
|
||
|
const ItemTile(this.item, {super.key});
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return ListTile(
|
||
|
onTap: () {
|
||
|
API().getItem(item).then((itemInfo) => Navigator.push(context,
|
||
|
MaterialPageRoute(builder: (context) => ItemView(item: itemInfo))));
|
||
|
},
|
||
|
title: Text(item),
|
||
|
);
|
||
|
}
|
||
|
}
|