diff --git a/lib/api.dart b/lib/api.dart index 19abb1f..dc7b14b 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -253,9 +253,9 @@ class API { return resp.map((x) => MinItem(x)).toList(); } - Future moveTransaction(String id, String new_location) async { + Future moveTransaction(String id, String newLocation) async { jsonDecode(await postRequest( - "$instance/transaction/$id/move", {"to": new_location})); + "$instance/transaction/$id/move", {"to": newLocation})); } Future getLocation(String id) async { @@ -360,11 +360,11 @@ class ConsumeInfo { class ItemVariantStat { late int amount; - late double total_price; + late double totalPrice; ItemVariantStat(Map 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 locations) { + String fullNamePath(Map 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 json) { - item_variant = json["item_variant"]; + itemVariant = json["item_variant"]; need = json["need"]; } } diff --git a/lib/main.dart b/lib/main.dart index 9a791ff..55f552d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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 { int pageIndex = 0; - List pages = [StatsPage(), ItemsPage(), FlowsPage(), LocationsPage()]; + List 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( diff --git a/lib/pages/consume.dart b/lib/pages/consume.dart index 231c528..f32c582 100644 --- a/lib/pages/consume.dart +++ b/lib/pages/consume.dart @@ -24,18 +24,19 @@ class _ConsumePageState extends State { super.initState(); } - Future _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(); + }); } } diff --git a/lib/pages/itemview.dart b/lib/pages/itemview.dart index 94bf1e9..d755f8f 100644 --- a/lib/pages/itemview.dart +++ b/lib/pages/itemview.dart @@ -75,7 +75,7 @@ class _ItemViewState extends State { 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); }, )); }, diff --git a/lib/pages/setup.dart b/lib/pages/setup.dart index d95944c..620413d 100644 --- a/lib/pages/setup.dart +++ b/lib/pages/setup.dart @@ -6,7 +6,7 @@ class SetupPage extends StatefulWidget { const SetupPage({super.key}); @override - _SetupPageState createState() => _SetupPageState(); + State createState() => _SetupPageState(); } class _SetupPageState extends State { diff --git a/lib/pages/supply.dart b/lib/pages/supply.dart index 64ac6a2..41103b5 100644 --- a/lib/pages/supply.dart +++ b/lib/pages/supply.dart @@ -25,18 +25,20 @@ class _SupplyPageState extends State { variant = widget.item.variants.keys.first; } - Future _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 { .map>((id) { return DropdownMenuItem( value: id, - child: Text( - locations[id]!.full_name_path(locations)), + child: + Text(locations[id]!.fullNamePath(locations)), ); }).toList(), onSaved: (value) {