cdb_ui/lib/main.dart

102 lines
2.4 KiB
Dart
Raw Normal View History

2024-09-04 18:05:04 +00:00
import 'package:cdb_ui/api.dart';
2024-09-24 16:00:13 +00:00
import 'package:cdb_ui/pages/flow/flows_page.dart';
2024-09-20 07:18:06 +00:00
import 'package:cdb_ui/pages/items.dart';
import 'package:cdb_ui/pages/locations.dart';
2024-09-08 15:45:48 +00:00
import 'package:cdb_ui/pages/setup.dart';
2024-12-15 02:59:32 +00:00
import 'package:cdb_ui/pages/home.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 {
2024-09-04 18:05:04 +00:00
runApp(const MyApp());
}
2024-10-07 19:48:48 +00:00
class MyApp extends StatefulWidget {
2024-09-04 18:05:04 +00:00
const MyApp({super.key});
2024-10-07 19:48:48 +00:00
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool init = false;
2024-10-08 08:11:18 +00:00
refresh() {
setState(() {});
}
2024-10-07 19:48:48 +00:00
@override
void initState() {
super.initState();
() async {
2024-10-08 08:11:18 +00:00
await API().init(refresh);
2024-10-07 19:48:48 +00:00
if (API().isInit()) {
await API().prefetch();
setState(() {
init = true;
});
}
}();
}
2024-09-04 18:05:04 +00:00
@override
Widget build(BuildContext context) {
return MaterialApp(
2024-10-07 19:48:48 +00:00
title: 'CDB',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.deepPurple, brightness: Brightness.dark),
useMaterial3: true,
),
home: API().isInit()
? (API().isPrefetched()
? const MyHomePage()
: const Scaffold(
2024-10-08 08:11:18 +00:00
body: Center(child: CircularProgressIndicator()),
2024-10-07 19:48:48 +00:00
))
: const SetupPage());
2024-09-04 18:05:04 +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-16 07:42:55 +00:00
List<Widget> pages = [
2024-12-15 02:59:32 +00:00
const HomePage(),
2024-09-16 07:42:55 +00:00
const ItemsPage(),
const FlowsPage(),
const LocationsPage()
];
2024-09-05 10:03:47 +00:00
@override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: BottomNavigationBar(
2024-09-15 13:15:46 +00:00
fixedColor: Colors.white,
unselectedItemColor: Colors.white70,
2024-09-05 10:03:47 +00:00
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
);
}
}