fix async nav + refactor
This commit is contained in:
parent
689fa13a7e
commit
bd054b0a9f
6 changed files with 52 additions and 44 deletions
16
lib/api.dart
16
lib/api.dart
|
@ -253,9 +253,9 @@ class API {
|
|||
return resp.map((x) => MinItem(x)).toList();
|
||||
}
|
||||
|
||||
Future<void> moveTransaction(String id, String new_location) async {
|
||||
Future<void> moveTransaction(String id, String newLocation) async {
|
||||
jsonDecode(await postRequest(
|
||||
"$instance/transaction/$id/move", {"to": new_location}));
|
||||
"$instance/transaction/$id/move", {"to": newLocation}));
|
||||
}
|
||||
|
||||
Future<Location> getLocation(String id) async {
|
||||
|
@ -360,11 +360,11 @@ class ConsumeInfo {
|
|||
|
||||
class ItemVariantStat {
|
||||
late int amount;
|
||||
late double total_price;
|
||||
late double totalPrice;
|
||||
|
||||
ItemVariantStat(Map<String, dynamic> json) {
|
||||
amount = json["amount"];
|
||||
total_price = json["total_price"];
|
||||
totalPrice = json["total_price"];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -388,11 +388,11 @@ class Location {
|
|||
conditions = json["conditions"] != null ? (json["conditions"]) : null;
|
||||
}
|
||||
|
||||
String full_name_path(Map<String, Location> locations) {
|
||||
String fullNamePath(Map<String, Location> locations) {
|
||||
var name = this.name;
|
||||
|
||||
if (parent != null) {
|
||||
name = "${locations[parent!]!.full_name_path(locations)} / $name";
|
||||
name = "${locations[parent!]!.fullNamePath(locations)} / $name";
|
||||
}
|
||||
|
||||
return name;
|
||||
|
@ -408,10 +408,10 @@ class LocationCondition {
|
|||
}
|
||||
|
||||
class MinItem {
|
||||
late String item_variant;
|
||||
late String itemVariant;
|
||||
late int need;
|
||||
MinItem(Map<String, dynamic> json) {
|
||||
item_variant = json["item_variant"];
|
||||
itemVariant = json["item_variant"];
|
||||
need = json["need"];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ class MyApp extends StatelessWidget {
|
|||
seedColor: Colors.deepPurple, brightness: Brightness.dark),
|
||||
useMaterial3: true,
|
||||
),
|
||||
home: API().isInit() ? MyHomePage() : SetupPage(),
|
||||
home: API().isInit() ? const MyHomePage() : const SetupPage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ class StatsPage extends StatelessWidget {
|
|||
future: _fetchData(),
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData) {
|
||||
return CircularProgressIndicator();
|
||||
return const CircularProgressIndicator();
|
||||
}
|
||||
|
||||
var data = snapshot.data!;
|
||||
|
@ -50,15 +50,17 @@ class StatsPage extends StatelessWidget {
|
|||
|
||||
return Column(
|
||||
children: [
|
||||
if (min.isNotEmpty) ListTile(title: Text("Items under Minimum")),
|
||||
if (min.isNotEmpty)
|
||||
const ListTile(title: Text("Items under Minimum")),
|
||||
...min.map((item) {
|
||||
return ListTile(
|
||||
title: Text(
|
||||
"Item ${item.item_variant} under minimum. Needs ${item.need} more."),
|
||||
"Item ${item.itemVariant} under minimum. Needs ${item.need} more."),
|
||||
);
|
||||
}).toList(),
|
||||
|
||||
if (expired.isNotEmpty) ListTile(title: Text("Expired Items")),
|
||||
if (expired.isNotEmpty)
|
||||
const ListTile(title: Text("Expired Items")),
|
||||
|
||||
// Mapping expired list to widgets
|
||||
...expired.map((item) {
|
||||
|
@ -80,7 +82,7 @@ class FlowsPage extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// todo : add locations tree view
|
||||
return Scaffold();
|
||||
return const Scaffold();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,7 +92,7 @@ class LocationsPage extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// todo : add locations tree view
|
||||
return Scaffold();
|
||||
return const Scaffold();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,7 +135,12 @@ class MyHomePage extends StatefulWidget {
|
|||
class _MyHomePageState extends State<MyHomePage> {
|
||||
int pageIndex = 0;
|
||||
|
||||
List<Widget> pages = [StatsPage(), ItemsPage(), FlowsPage(), LocationsPage()];
|
||||
List<Widget> pages = [
|
||||
const StatsPage(),
|
||||
const ItemsPage(),
|
||||
const FlowsPage(),
|
||||
const LocationsPage()
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -169,11 +176,9 @@ class ItemCard extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InkWell(
|
||||
onTap: () async {
|
||||
var itemInfo = await API().getItem(item);
|
||||
|
||||
Navigator.push(context,
|
||||
MaterialPageRoute(builder: (context) => ItemView(item: itemInfo)));
|
||||
onTap: () {
|
||||
API().getItem(item).then((itemInfo) => Navigator.push(context,
|
||||
MaterialPageRoute(builder: (context) => ItemView(item: itemInfo))));
|
||||
},
|
||||
child: Row(children: [
|
||||
/*Image.network(
|
||||
|
|
|
@ -24,18 +24,19 @@ class _ConsumePageState extends State<ConsumePage> {
|
|||
super.initState();
|
||||
}
|
||||
|
||||
Future<void> _consume() async {
|
||||
void _consume() {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
_formKey.currentState!.save();
|
||||
|
||||
await API()
|
||||
.consumeItem(widget.transaction, _selectedDestination, "${_price} €");
|
||||
|
||||
API()
|
||||
.consumeItem(widget.transaction, _selectedDestination, "$_price €")
|
||||
.then((_) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Item consumed successfully!')),
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
widget.refresh();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ class _ItemViewState extends State<ItemView> {
|
|||
children: [
|
||||
Text("Amount: ${stat.amount}"),
|
||||
Text(
|
||||
"Total Cost: ${stat.total_price.toStringAsFixed(2)}")
|
||||
"Total Cost: ${stat.totalPrice.toStringAsFixed(2)}")
|
||||
],
|
||||
);
|
||||
},
|
||||
|
@ -125,7 +125,7 @@ class TransactionCard extends StatelessWidget {
|
|||
onTap: () {
|
||||
Navigator.of(context).push(MaterialPageRoute(
|
||||
builder: (context) {
|
||||
return ConsumePage(t.uuid, t.item, t.variant, this.refresh);
|
||||
return ConsumePage(t.uuid, t.item, t.variant, refresh);
|
||||
},
|
||||
));
|
||||
},
|
||||
|
|
|
@ -6,7 +6,7 @@ class SetupPage extends StatefulWidget {
|
|||
const SetupPage({super.key});
|
||||
|
||||
@override
|
||||
_SetupPageState createState() => _SetupPageState();
|
||||
State<SetupPage> createState() => _SetupPageState();
|
||||
}
|
||||
|
||||
class _SetupPageState extends State<SetupPage> {
|
||||
|
|
|
@ -25,18 +25,20 @@ class _SupplyPageState extends State<SupplyPage> {
|
|||
variant = widget.item.variants.keys.first;
|
||||
}
|
||||
|
||||
Future<void> _supply() async {
|
||||
void _supply() {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
_formKey.currentState!.save();
|
||||
|
||||
await API().supplyItem(widget.item.name, variant, "${_price} €",
|
||||
_selectedOrigin, _selectedLocation);
|
||||
|
||||
API()
|
||||
.supplyItem(widget.item.name, variant, "$_price €", _selectedOrigin,
|
||||
_selectedLocation)
|
||||
.then((_) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Item added successfully!')),
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
widget.refresh();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,8 +167,8 @@ class _SupplyPageState extends State<SupplyPage> {
|
|||
.map<DropdownMenuItem<String>>((id) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: id,
|
||||
child: Text(
|
||||
locations[id]!.full_name_path(locations)),
|
||||
child:
|
||||
Text(locations[id]!.fullNamePath(locations)),
|
||||
);
|
||||
}).toList(),
|
||||
onSaved: (value) {
|
||||
|
|
Loading…
Reference in a new issue