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,
),
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Home Page")),
body: Column(children: [
Container(
child: Row(children: const [Text("Stats about everything")]),
),
FutureBuilder(
future: API().getItems(),
builder: (context, snapshot) {
print(snapshot);
if (snapshot.hasData) {
var items = snapshot.data!;
return Expanded(
child: GridView.count(
crossAxisCount: 2,
children: items.map((x) {
return ItemCard(x);
}).toList(),
));
}
return CircularProgressIndicator();
})
]),
);
}
}
class ItemCard extends StatelessWidget {
late String item;
ItemCard(this.item);
@override
Widget build(BuildContext context) {
return InkWell(
onTap: () async {
var item_info = await API().getItem(item);
Navigator.push(context,
MaterialPageRoute(builder: (context) => ItemView(item: item_info)));
},
child: Row(children: [
Image.network(
API().getImageURL(item),
width: 128,
height: 128,
),
Text("$item")
]),
);
}
}