cdb_ui/lib/main.dart

82 lines
1.9 KiB
Dart
Raw Normal View History

2024-09-04 18:05:04 +00:00
import 'package:cdb_ui/api.dart';
import 'package:cdb_ui/itemview.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'CDB',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
2024-09-05 08:12:56 +00:00
home: const HomePage(),
2024-09-04 18:05:04 +00:00
);
}
}
class HomePage extends StatelessWidget {
2024-09-05 08:12:56 +00:00
const HomePage({super.key});
2024-09-04 18:05:04 +00:00
@override
Widget build(BuildContext context) {
return Scaffold(
2024-09-05 08:12:56 +00:00
appBar: AppBar(title: const Text("Home Page")),
2024-09-04 18:05:04 +00:00
body: Column(children: [
2024-09-05 08:12:56 +00:00
const Row(children: [Text("Stats about everything")]),
2024-09-04 18:05:04 +00:00
FutureBuilder(
future: API().getItems(),
builder: (context, snapshot) {
2024-09-05 08:12:56 +00:00
if (!snapshot.hasData) {
return const CircularProgressIndicator();
2024-09-04 18:05:04 +00:00
}
2024-09-05 08:12:56 +00:00
var items = snapshot.data!;
return Expanded(
child: GridView.count(
crossAxisCount: 2,
children: items.map((x) {
return ItemCard(x);
}).toList(),
));
2024-09-04 18:05:04 +00:00
})
]),
);
}
}
class ItemCard extends StatelessWidget {
2024-09-05 08:12:56 +00:00
final String item;
2024-09-04 18:05:04 +00:00
2024-09-05 08:12:56 +00:00
const ItemCard(this.item, {super.key});
2024-09-04 18:05:04 +00:00
@override
Widget build(BuildContext context) {
return InkWell(
onTap: () async {
2024-09-05 08:12:56 +00:00
var itemInfo = await API().getItem(item);
2024-09-04 18:05:04 +00:00
Navigator.push(context,
2024-09-05 08:12:56 +00:00
MaterialPageRoute(builder: (context) => ItemView(item: itemInfo)));
2024-09-04 18:05:04 +00:00
},
child: Row(children: [
Image.network(
API().getImageURL(item),
width: 128,
height: 128,
),
2024-09-05 08:12:56 +00:00
Text(item)
2024-09-04 18:05:04 +00:00
]),
);
}
}