2024-09-04 18:05:04 +00:00
|
|
|
import 'package:cdb_ui/api.dart';
|
2024-09-07 21:56:52 +00:00
|
|
|
import 'package:cdb_ui/pages/itemview.dart';
|
2024-09-08 15:45:48 +00:00
|
|
|
import 'package:cdb_ui/pages/setup.dart';
|
2024-09-04 18:05:04 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2024-09-08 15:45:48 +00:00
|
|
|
Future<void> main() async {
|
|
|
|
await API().init();
|
2024-09-04 18:05:04 +00:00
|
|
|
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(
|
2024-09-07 22:51:18 +00:00
|
|
|
colorScheme: ColorScheme.fromSeed(
|
|
|
|
seedColor: Colors.deepPurple, brightness: Brightness.dark),
|
2024-09-04 18:05:04 +00:00
|
|
|
useMaterial3: true,
|
|
|
|
),
|
2024-09-08 15:45:48 +00:00
|
|
|
home: API().isInit() ? MyHomePage() : SetupPage(),
|
2024-09-04 18:05:04 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-05 10:03:47 +00:00
|
|
|
class StatsPage extends StatelessWidget {
|
|
|
|
const StatsPage({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-09-07 21:56:52 +00:00
|
|
|
// todo : add global statistics
|
|
|
|
return Scaffold();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class FlowsPage extends StatelessWidget {
|
|
|
|
const FlowsPage({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
// todo : add locations tree view
|
2024-09-05 10:03:47 +00:00
|
|
|
return Scaffold();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class LocationsPage extends StatelessWidget {
|
|
|
|
const LocationsPage({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-09-07 21:56:52 +00:00
|
|
|
// todo : add locations tree view
|
2024-09-05 10:03:47 +00:00
|
|
|
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!;
|
|
|
|
|
2024-09-07 21:56:52 +00:00
|
|
|
return GridView.count(
|
2024-09-05 10:03:47 +00:00
|
|
|
crossAxisCount: 2,
|
|
|
|
children: items.map((x) {
|
|
|
|
return ItemCard(x);
|
|
|
|
}).toList(),
|
2024-09-07 21:56:52 +00:00
|
|
|
);
|
2024-09-05 10:03:47 +00:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyHomePage extends StatefulWidget {
|
|
|
|
const MyHomePage({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<MyHomePage> createState() => _MyHomePageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _MyHomePageState extends State<MyHomePage> {
|
|
|
|
int pageIndex = 0;
|
|
|
|
|
2024-09-07 21:56:52 +00:00
|
|
|
List<Widget> pages = [StatsPage(), ItemsPage(), FlowsPage(), LocationsPage()];
|
2024-09-05 10:03:47 +00:00
|
|
|
|
|
|
|
@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"),
|
2024-09-07 21:56:52 +00:00
|
|
|
BottomNavigationBarItem(icon: Icon(Icons.receipt), label: "Flows"),
|
2024-09-05 10:03:47 +00:00
|
|
|
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: [
|
2024-09-07 21:56:52 +00:00
|
|
|
/*Image.network(
|
2024-09-04 18:05:04 +00:00
|
|
|
API().getImageURL(item),
|
|
|
|
width: 128,
|
|
|
|
height: 128,
|
2024-09-07 21:56:52 +00:00
|
|
|
),*/
|
2024-09-05 08:12:56 +00:00
|
|
|
Text(item)
|
2024-09-04 18:05:04 +00:00
|
|
|
]),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|