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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var currentQuantity = widget.quantity;
|
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
margin: const EdgeInsets.all(8.0),
|
margin: const EdgeInsets.all(8.0),
|
||||||
|
@ -71,13 +70,11 @@ class _CartBoxState extends State<CartBox> {
|
||||||
children: [
|
children: [
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: (){
|
onPressed: (){
|
||||||
currentQuantity++;
|
|
||||||
widget.plus();
|
widget.plus();
|
||||||
setState(() {});
|
|
||||||
},
|
},
|
||||||
child: const Text("+")
|
child: const Text("+")
|
||||||
),
|
),
|
||||||
Text(currentQuantity.toString(),
|
Text(widget.quantity.toString(),
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 15,
|
fontSize: 15,
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
|
@ -85,9 +82,7 @@ class _CartBoxState extends State<CartBox> {
|
||||||
),
|
),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: (){
|
onPressed: (){
|
||||||
currentQuantity--;
|
|
||||||
widget.minus();
|
widget.minus();
|
||||||
setState(() {});
|
|
||||||
},
|
},
|
||||||
child: const Text("-")
|
child: const Text("-")
|
||||||
)
|
)
|
||||||
|
|
|
@ -12,6 +12,8 @@ class Cart extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _CartState extends State<Cart> {
|
class _CartState extends State<Cart> {
|
||||||
|
Future<dynamic> _viewCart = viewCart();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
@ -22,7 +24,7 @@ class _CartState extends State<Cart> {
|
||||||
backgroundColor: const Color(0xff212226),
|
backgroundColor: const Color(0xff212226),
|
||||||
),
|
),
|
||||||
body: FutureBuilder<dynamic>(
|
body: FutureBuilder<dynamic>(
|
||||||
future: viewCart(),
|
future: _viewCart,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (snapshot.hasData) {
|
if (snapshot.hasData) {
|
||||||
var data = snapshot.data;
|
var data = snapshot.data;
|
||||||
|
@ -41,12 +43,21 @@ class _CartState extends State<Cart> {
|
||||||
quantity: data[index]["quantity"],
|
quantity: data[index]["quantity"],
|
||||||
plus: () {
|
plus: () {
|
||||||
addToCart(data[index]["product_id"]);
|
addToCart(data[index]["product_id"]);
|
||||||
|
setState(() {
|
||||||
|
_viewCart = viewCart();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
minus: () {
|
minus: () {
|
||||||
removeFromCart(data[index]["product_id"], false);
|
removeFromCart(data[index]["product_id"], false);
|
||||||
|
setState(() {
|
||||||
|
_viewCart = viewCart();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
remove: () {
|
remove: () {
|
||||||
removeFromCart(data[index]["product_id"], true);
|
removeFromCart(data[index]["product_id"], true);
|
||||||
|
setState(() {
|
||||||
|
_viewCart = viewCart();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue