fix async nav + refactor

This commit is contained in:
JMARyA 2024-09-16 09:42:55 +02:00
parent 689fa13a7e
commit bd054b0a9f
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
6 changed files with 52 additions and 44 deletions

View file

@ -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}");
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Item consumed successfully!')),
);
Navigator.of(context).pop();
widget.refresh();
API()
.consumeItem(widget.transaction, _selectedDestination, "$_price")
.then((_) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Item consumed successfully!')),
);
Navigator.of(context).pop();
widget.refresh();
});
}
}

View file

@ -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);
},
));
},

View file

@ -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> {

View file

@ -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);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Item added successfully!')),
);
Navigator.of(context).pop();
widget.refresh();
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) {