diff --git a/lib/pages/consume.dart b/lib/pages/consume.dart index 231bcec..9888126 100644 --- a/lib/pages/consume.dart +++ b/lib/pages/consume.dart @@ -3,13 +3,10 @@ import 'package:cdb_ui/pages/supply.dart'; import 'package:flutter/material.dart'; class ConsumePage extends StatefulWidget { - final String item; - final String variant; - final String transaction; + final Transaction transaction; final Function refresh; - const ConsumePage(this.transaction, this.item, this.variant, this.refresh, - {super.key}); + const ConsumePage(this.transaction, this.refresh, {super.key}); @override State createState() => _ConsumePageState(); @@ -30,7 +27,8 @@ class _ConsumePageState extends State { _formKey.currentState!.save(); API() - .consumeItem(widget.transaction, _selectedDestination, "$_price €") + .consumeItem( + widget.transaction.uuid, _selectedDestination, "$_price €") .then((_) { ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('Item consumed successfully!')), @@ -48,8 +46,8 @@ class _ConsumePageState extends State { title: const Text('Consume Item'), ), body: FutureBuilder( - future: - API().getUniqueField(widget.item, widget.variant, "destination"), + future: API().getUniqueField( + widget.transaction.item, widget.transaction.variant, "destination"), builder: (context, snapshot) { if (!snapshot.hasData) { return const Center(child: CircularProgressIndicator()); diff --git a/lib/pages/transaction.dart b/lib/pages/transaction.dart index 697bc51..9a2375f 100644 --- a/lib/pages/transaction.dart +++ b/lib/pages/transaction.dart @@ -6,8 +6,9 @@ import 'package:qr_bar_code/qr/qr.dart'; class TransactionPage extends StatelessWidget { final Transaction transaction; + final Function? refresh; - const TransactionPage(this.transaction, {super.key}); + const TransactionPage(this.transaction, {this.refresh, super.key}); @override Widget build(BuildContext context) { @@ -48,6 +49,15 @@ class TransactionPage extends StatelessWidget { // todo : chart with price history ], ), + floatingActionButton: FloatingActionButton( + onPressed: () { + Navigator.of(context).pushReplacement(MaterialPageRoute( + builder: (context) { + return ConsumePage(transaction, refresh ?? () {}); + }, + )); + }, + child: const Icon(Icons.receipt_long)), ); } } @@ -64,7 +74,7 @@ class TransactionCard extends StatelessWidget { onTap: () { Navigator.of(context).push(MaterialPageRoute( builder: (context) { - return ConsumePage(t.uuid, t.item, t.variant, refresh); + return ConsumePage(t, refresh); }, )); },