Fix bug (Cart UI not updating)
This commit is contained in:
parent
d74682edfd
commit
31e1c381b6
2 changed files with 13 additions and 7 deletions
|
@ -19,7 +19,6 @@ class _CartBoxState extends State<CartBox> {
|
|||
|
||||
@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<CartBox> {
|
|||
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<CartBox> {
|
|||
),
|
||||
ElevatedButton(
|
||||
onPressed: (){
|
||||
currentQuantity--;
|
||||
widget.minus();
|
||||
setState(() {});
|
||||
},
|
||||
child: const Text("-")
|
||||
)
|
||||
|
|
|
@ -12,6 +12,8 @@ class Cart extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _CartState extends State<Cart> {
|
||||
Future<dynamic> _viewCart = viewCart();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
|
@ -22,7 +24,7 @@ class _CartState extends State<Cart> {
|
|||
backgroundColor: const Color(0xff212226),
|
||||
),
|
||||
body: FutureBuilder<dynamic>(
|
||||
future: viewCart(),
|
||||
future: _viewCart,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
var data = snapshot.data;
|
||||
|
@ -41,12 +43,21 @@ class _CartState extends State<Cart> {
|
|||
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();
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue