import 'package:cdb_ui/api.dart'; import 'package:cdb_ui/pages/flow/flows_page.dart'; import 'package:cdb_ui/pages/items.dart'; import 'package:cdb_ui/pages/locations.dart'; import 'package:cdb_ui/pages/setup.dart'; import 'package:cdb_ui/pages/home.dart'; import 'package:flutter/material.dart'; Future main() async { runApp(const MyApp()); } class MyApp extends StatefulWidget { const MyApp({super.key}); @override State createState() => _MyAppState(); } class _MyAppState extends State { bool init = false; refresh() { setState(() {}); } @override void initState() { super.initState(); () async { await API().init(refresh); if (API().isInit()) { await API().prefetch(); setState(() { init = true; }); } }(); } @override Widget build(BuildContext context) { return MaterialApp( title: 'CDB', theme: ThemeData( colorScheme: ColorScheme.fromSeed( seedColor: Colors.deepPurple, brightness: Brightness.dark), useMaterial3: true, ), home: API().isInit() ? (API().isPrefetched() ? const MyHomePage() : const Scaffold( body: Center(child: CircularProgressIndicator()), )) : const SetupPage()); } } class MyHomePage extends StatefulWidget { const MyHomePage({super.key}); @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { int pageIndex = 0; List pages = [ const HomePage(), const ItemsPage(), const FlowsPage(), const LocationsPage() ]; @override Widget build(BuildContext context) { return Scaffold( bottomNavigationBar: BottomNavigationBar( fixedColor: Colors.white, unselectedItemColor: Colors.white70, items: const [ BottomNavigationBarItem(icon: Icon(Icons.home), label: "Home"), BottomNavigationBarItem( icon: Icon(Icons.data_object), label: "Items"), BottomNavigationBarItem(icon: Icon(Icons.receipt), label: "Flows"), BottomNavigationBarItem( icon: Icon(Icons.location_city), label: "Locations"), ], currentIndex: pageIndex, onTap: (value) { setState(() { pageIndex = value; }); }, ), body: pages[pageIndex], ); } }