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 LocationCondition? conditions;
Location.zero() {
id = "";
name = "";
parent = null;
conditions = null;
}
Location(Map<String, dynamic> json) {
id = json["id"];
name = json["name"];
parent = json["parent"];
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 {

View file

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

View file

@ -26,11 +26,19 @@ class _ItemViewState extends State<ItemView> {
),
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(

View file

@ -53,8 +53,8 @@ class _SupplyPageState extends State<SupplyPage> {
return const Center(child: CircularProgressIndicator());
}
var data = snapshot.data as Map<String, List<dynamic>>;
var locations = data['locations']!;
var data = snapshot.data as Map<String, dynamic>;
var locations = data['locations']! as Map<String, Location>;
var origins = data['origins']! as List<String>;
return Padding(
@ -144,37 +144,47 @@ class _SupplyPageState extends State<SupplyPage> {
const SizedBox(height: 16),
// Location Dropdown
DropdownButtonFormField<String>(
hint: const Text('Select Location'),
value: _selectedLocation,
onChanged: (value) {
setState(() {
_selectedLocation = value!;
});
},
items: locations.map<DropdownMenuItem<String>>((location) {
return DropdownMenuItem<String>(
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<String>(
hint: const Text('Select Location'),
value: _selectedLocation,
onChanged: (value) {
setState(() {
_selectedLocation = value!;
});
},
items: locations.keys
.map<DropdownMenuItem<String>>((id) {
return DropdownMenuItem<String>(
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<SupplyPage> {
);
}
Future<Map<String, List<dynamic>>> _fetchData() async {
var locations_map = await API().getLocations();
Future<Map<String, dynamic>> _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};
}
}