This commit is contained in:
JMARyA 2024-09-15 15:15:46 +02:00
parent 91beacceb6
commit 549df5ff22
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
4 changed files with 112 additions and 38 deletions

View file

@ -360,12 +360,29 @@ class Location {
late String? parent; late String? parent;
late LocationCondition? conditions; late LocationCondition? conditions;
Location.zero() {
id = "";
name = "";
parent = null;
conditions = null;
}
Location(Map<String, dynamic> json) { Location(Map<String, dynamic> json) {
id = json["id"]; id = json["id"];
name = json["name"]; name = json["name"];
parent = json["parent"]; parent = json["parent"];
conditions = json["conditions"] != null ? (json["conditions"]) : null; conditions = json["conditions"] != null ? (json["conditions"]) : null;
} }
String full_name_path(Map<String, Location> locations) {
var name = this.name;
if (parent != null) {
name = "${locations[parent!]!.full_name_path(locations)} / $name";
}
return name;
}
} }
class LocationCondition { class LocationCondition {

View file

@ -29,10 +29,48 @@ class MyApp extends StatelessWidget {
class StatsPage extends StatelessWidget { class StatsPage extends StatelessWidget {
const StatsPage({super.key}); const StatsPage({super.key});
Future<(List<MinItem>, List<Transaction>)> _fetchData() async {
return (await API().getItemsUnderMin(), await API().getExpiredItems());
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// todo : add global statistics // 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<MyHomePage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
bottomNavigationBar: BottomNavigationBar( bottomNavigationBar: BottomNavigationBar(
fixedColor: Colors.white,
unselectedItemColor: Colors.white70,
items: const [ items: const [
BottomNavigationBarItem(icon: Icon(Icons.home), label: "Home"), BottomNavigationBarItem(icon: Icon(Icons.home), label: "Home"),
BottomNavigationBarItem( BottomNavigationBarItem(

View file

@ -26,11 +26,19 @@ class _ItemViewState extends State<ItemView> {
), ),
body: Column(children: [ body: Column(children: [
Row( Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [ children: [
SizedBox(width: 28),
const Align( const Align(
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
child: Placeholder(), child: Placeholder(
fallbackWidth: 100,
fallbackHeight: 100,
),
), // todo ), // todo
SizedBox(
width: 16.0,
),
Column( Column(
children: [ children: [
Text( Text(

View file

@ -53,8 +53,8 @@ class _SupplyPageState extends State<SupplyPage> {
return const Center(child: CircularProgressIndicator()); return const Center(child: CircularProgressIndicator());
} }
var data = snapshot.data as Map<String, List<dynamic>>; var data = snapshot.data as Map<String, dynamic>;
var locations = data['locations']!; var locations = data['locations']! as Map<String, Location>;
var origins = data['origins']! as List<String>; var origins = data['origins']! as List<String>;
return Padding( return Padding(
@ -144,37 +144,47 @@ class _SupplyPageState extends State<SupplyPage> {
const SizedBox(height: 16), const SizedBox(height: 16),
// Location Dropdown // Location Dropdown
DropdownButtonFormField<String>( Row(
hint: const Text('Select Location'), children: [
value: _selectedLocation, Expanded(
onChanged: (value) { child: DropdownButtonFormField<String>(
setState(() { hint: const Text('Select Location'),
_selectedLocation = value!; value: _selectedLocation,
}); onChanged: (value) {
}, setState(() {
items: locations.map<DropdownMenuItem<String>>((location) { _selectedLocation = value!;
return DropdownMenuItem<String>( });
value: location, },
child: Text(location), items: locations.keys
); .map<DropdownMenuItem<String>>((id) {
}).toList(), return DropdownMenuItem<String>(
onSaved: (value) { value: id,
_selectedLocation = value!; child: Text(
}, locations[id]!.full_name_path(locations)),
), );
}).toList(),
IconButton( onSaved: (value) {
onPressed: () { _selectedLocation = value!;
QrBarCodeScannerDialog().getScannedQrBarCode( },
context: context, ),
onCode: (code) { ),
setState(() { SizedBox(
_selectedLocation = code!; 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), const SizedBox(height: 20),
@ -193,12 +203,11 @@ class _SupplyPageState extends State<SupplyPage> {
); );
} }
Future<Map<String, List<dynamic>>> _fetchData() async { Future<Map<String, dynamic>> _fetchData() async {
var locations_map = await API().getLocations(); var locations = await API().getLocations();
var origins = await API().getUniqueField(widget.item.id, variant, "origin"); var origins = await API().getUniqueField(widget.item.id, variant, "origin");
origins.insert(0, ""); origins.insert(0, "");
var locations = locations_map.keys.toList(); locations[""] = Location.zero();
locations.insert(0, "");
return {'locations': locations, 'origins': origins}; return {'locations': locations, 'origins': origins};
} }
} }