cdb_ui/lib/main.dart

139 lines
3.1 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 10:03:47 +00:00
home: const MyHomePage(),
2024-09-04 18:05:04 +00:00
);
}
}
2024-09-05 10:03:47 +00:00
// todo : homepage with tabs
// tab 1: home stats
// tab 2: item list
// tab 3: locations
class StatsPage extends StatelessWidget {
const StatsPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold();
}
}
class LocationsPage extends StatelessWidget {
const LocationsPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold();
}
}
class ItemsPage extends StatelessWidget {
const ItemsPage({super.key});
2024-09-05 08:12:56 +00:00
2024-09-04 18:05:04 +00:00
@override
Widget build(BuildContext context) {
return Scaffold(
2024-09-05 10:03:47 +00:00
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 Expanded(
child: GridView.count(
crossAxisCount: 2,
children: items.map((x) {
return ItemCard(x);
}).toList(),
));
}),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int pageIndex = 0;
List<Widget> pages = [StatsPage(), ItemsPage(), LocationsPage()];
@override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: BottomNavigationBar(
items: const [
BottomNavigationBarItem(icon: Icon(Icons.home), label: "Home"),
BottomNavigationBarItem(
icon: Icon(Icons.data_object), label: "Items"),
BottomNavigationBarItem(
icon: Icon(Icons.location_city), label: "Locations"),
],
currentIndex: pageIndex,
onTap: (value) {
setState(() {
pageIndex = value;
});
},
),
body: pages[pageIndex],
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
]),
);
}
}