diff --git a/lib/components/cart_box.dart b/lib/components/cart_box.dart index 9d423dc..04fda98 100644 --- a/lib/components/cart_box.dart +++ b/lib/components/cart_box.dart @@ -19,7 +19,6 @@ class _CartBoxState extends State { @override Widget build(BuildContext context) { - var currentQuantity = widget.quantity; return Container( margin: const EdgeInsets.all(8.0), @@ -71,13 +70,11 @@ class _CartBoxState extends State { children: [ ElevatedButton( onPressed: (){ - currentQuantity++; widget.plus(); - setState(() {}); }, child: const Text("+") ), - Text(currentQuantity.toString(), + Text(widget.quantity.toString(), style: const TextStyle( fontSize: 15, color: Colors.white, @@ -85,9 +82,7 @@ class _CartBoxState extends State { ), ElevatedButton( onPressed: (){ - currentQuantity--; widget.minus(); - setState(() {}); }, child: const Text("-") ) diff --git a/lib/screens/cart.dart b/lib/screens/cart.dart index cdc44dc..e709261 100644 --- a/lib/screens/cart.dart +++ b/lib/screens/cart.dart @@ -12,6 +12,8 @@ class Cart extends StatefulWidget { } class _CartState extends State { + Future _viewCart = viewCart(); + @override Widget build(BuildContext context) { return Scaffold( @@ -22,7 +24,7 @@ class _CartState extends State { backgroundColor: const Color(0xff212226), ), body: FutureBuilder( - future: viewCart(), + future: _viewCart, builder: (context, snapshot) { if (snapshot.hasData) { var data = snapshot.data; @@ -41,12 +43,21 @@ class _CartState extends State { quantity: data[index]["quantity"], plus: () { addToCart(data[index]["product_id"]); + setState(() { + _viewCart = viewCart(); + }); }, minus: () { removeFromCart(data[index]["product_id"], false); + setState(() { + _viewCart = viewCart(); + }); }, remove: () { removeFromCart(data[index]["product_id"], true); + setState(() { + _viewCart = viewCart(); + }); } ); }