import 'package:cdb_ui/api.dart'; import 'package:cdb_ui/pages/itemview.dart'; import 'package:cdb_ui/pages/setup.dart'; import 'package:flutter/material.dart'; Future main() async { await API().init(); 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, brightness: Brightness.dark), useMaterial3: true, ), home: API().isInit() ? MyHomePage() : SetupPage(), ); } } // todo : add setup with instance and token auth (api) class StatsPage extends StatelessWidget { const StatsPage({super.key}); @override Widget build(BuildContext context) { // todo : add global statistics return Scaffold(); } } class FlowsPage extends StatelessWidget { const FlowsPage({super.key}); @override Widget build(BuildContext context) { // todo : add locations tree view return Scaffold(); } } class LocationsPage extends StatelessWidget { const LocationsPage({super.key}); @override Widget build(BuildContext context) { // todo : add locations tree view return Scaffold(); } } class ItemsPage extends StatelessWidget { const ItemsPage({super.key}); @override Widget build(BuildContext context) { return Scaffold( 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 GridView.count( crossAxisCount: 2, children: items.map((x) { return ItemCard(x); }).toList(), ); }), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({super.key}); @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { int pageIndex = 0; List pages = [StatsPage(), ItemsPage(), FlowsPage(), 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.receipt), label: "Flows"), BottomNavigationBarItem( icon: Icon(Icons.location_city), label: "Locations"), ], currentIndex: pageIndex, onTap: (value) { setState(() { pageIndex = value; }); }, ), body: pages[pageIndex], ); } } class ItemCard extends StatelessWidget { final String item; const ItemCard(this.item, {super.key}); @override Widget build(BuildContext context) { return InkWell( onTap: () async { var itemInfo = await API().getItem(item); Navigator.push(context, MaterialPageRoute(builder: (context) => ItemView(item: itemInfo))); }, child: Row(children: [ /*Image.network( API().getImageURL(item), width: 128, height: 128, ),*/ Text(item) ]), ); } }