diff --git a/lib/api.dart b/lib/api.dart index 3afc6ba..094f885 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -360,12 +360,29 @@ class Location { late String? parent; late LocationCondition? conditions; + Location.zero() { + id = ""; + name = ""; + parent = null; + conditions = null; + } + Location(Map json) { id = json["id"]; name = json["name"]; parent = json["parent"]; conditions = json["conditions"] != null ? (json["conditions"]) : null; } + + String full_name_path(Map locations) { + var name = this.name; + + if (parent != null) { + name = "${locations[parent!]!.full_name_path(locations)} / $name"; + } + + return name; + } } class LocationCondition { diff --git a/lib/main.dart b/lib/main.dart index 689c7fc..9a791ff 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -29,10 +29,48 @@ class MyApp extends StatelessWidget { class StatsPage extends StatelessWidget { const StatsPage({super.key}); + Future<(List, List)> _fetchData() async { + return (await API().getItemsUnderMin(), await API().getExpiredItems()); + } + @override Widget build(BuildContext context) { // todo : add global statistics - return Scaffold(); + return Scaffold( + body: FutureBuilder( + future: _fetchData(), + builder: (context, snapshot) { + if (!snapshot.hasData) { + return CircularProgressIndicator(); + } + + var data = snapshot.data!; + var min = data.$1; + var expired = data.$2; + + return Column( + children: [ + if (min.isNotEmpty) ListTile(title: Text("Items under Minimum")), + ...min.map((item) { + return ListTile( + title: Text( + "Item ${item.item_variant} under minimum. Needs ${item.need} more."), + ); + }).toList(), + + if (expired.isNotEmpty) ListTile(title: Text("Expired Items")), + + // Mapping expired list to widgets + ...expired.map((item) { + return ListTile( + title: TransactionCard(item, () {}), + ); + }).toList(), + ], + ); + }, + ), + ); } } @@ -101,6 +139,8 @@ class _MyHomePageState extends State { Widget build(BuildContext context) { return Scaffold( bottomNavigationBar: BottomNavigationBar( + fixedColor: Colors.white, + unselectedItemColor: Colors.white70, items: const [ BottomNavigationBarItem(icon: Icon(Icons.home), label: "Home"), BottomNavigationBarItem( diff --git a/lib/pages/itemview.dart b/lib/pages/itemview.dart index 4543fd0..5503716 100644 --- a/lib/pages/itemview.dart +++ b/lib/pages/itemview.dart @@ -26,11 +26,19 @@ class _ItemViewState extends State { ), body: Column(children: [ Row( + mainAxisAlignment: MainAxisAlignment.start, children: [ + SizedBox(width: 28), const Align( alignment: Alignment.centerLeft, - child: Placeholder(), + child: Placeholder( + fallbackWidth: 100, + fallbackHeight: 100, + ), ), // todo + SizedBox( + width: 16.0, + ), Column( children: [ Text( diff --git a/lib/pages/supply.dart b/lib/pages/supply.dart index 49705ee..b3de61b 100644 --- a/lib/pages/supply.dart +++ b/lib/pages/supply.dart @@ -53,8 +53,8 @@ class _SupplyPageState extends State { return const Center(child: CircularProgressIndicator()); } - var data = snapshot.data as Map>; - var locations = data['locations']!; + var data = snapshot.data as Map; + var locations = data['locations']! as Map; var origins = data['origins']! as List; return Padding( @@ -144,37 +144,47 @@ class _SupplyPageState extends State { const SizedBox(height: 16), // Location Dropdown - DropdownButtonFormField( - hint: const Text('Select Location'), - value: _selectedLocation, - onChanged: (value) { - setState(() { - _selectedLocation = value!; - }); - }, - items: locations.map>((location) { - return DropdownMenuItem( - value: location, - child: Text(location), - ); - }).toList(), - onSaved: (value) { - _selectedLocation = value!; - }, - ), - - IconButton( - onPressed: () { - QrBarCodeScannerDialog().getScannedQrBarCode( - context: context, - onCode: (code) { - setState(() { - _selectedLocation = code!; - }); + Row( + children: [ + Expanded( + child: DropdownButtonFormField( + hint: const Text('Select Location'), + value: _selectedLocation, + onChanged: (value) { + setState(() { + _selectedLocation = value!; + }); + }, + items: locations.keys + .map>((id) { + return DropdownMenuItem( + value: id, + child: Text( + locations[id]!.full_name_path(locations)), + ); + }).toList(), + onSaved: (value) { + _selectedLocation = value!; + }, + ), + ), + SizedBox( + width: 12, + ), + IconButton( + onPressed: () { + QrBarCodeScannerDialog().getScannedQrBarCode( + context: context, + onCode: (code) { + setState(() { + _selectedLocation = code!; + }); + }, + ); }, - ); - }, - icon: const Icon(Icons.qr_code), + icon: const Icon(Icons.qr_code), + ), + ], ), const SizedBox(height: 20), @@ -193,12 +203,11 @@ class _SupplyPageState extends State { ); } - Future>> _fetchData() async { - var locations_map = await API().getLocations(); + Future> _fetchData() async { + var locations = await API().getLocations(); var origins = await API().getUniqueField(widget.item.id, variant, "origin"); origins.insert(0, ""); - var locations = locations_map.keys.toList(); - locations.insert(0, ""); + locations[""] = Location.zero(); return {'locations': locations, 'origins': origins}; } }