Skip to content

Commit

Permalink
adding show dialog for if user is sure to remove the item form the cart
Browse files Browse the repository at this point in the history
  • Loading branch information
amirhossein-jahangiri committed Aug 22, 2021
1 parent 8922e42 commit c5d904f
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions lib/widgets/cart_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,57 @@ class CartItem extends StatelessWidget {
this.title,
this.price,
this.quantitiy,
});
});

@override
Widget build(BuildContext context) {
//final cart = Provider.of<Cart>(context , listen: false);
return Dismissible(
key: ValueKey(id),
direction: DismissDirection.endToStart,
onDismissed: (direction){
confirmDismiss: (direction) => showDialog(
context: context,
barrierDismissible: false,
builder: (context) => AlertDialog(
title: Text('Are you sure?'),
content: Text('Do you want to remove the item from the cart?'),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.of(context).pop(false),
child: Text('No'),
),
TextButton(
onPressed: () => Navigator.of(context).pop(true),
child: Text('Yes'),
),
],
),
),
onDismissed: (direction) {
log('product id is ${productId!}');
Provider.of<Cart>(context , listen: false).removeItem(productId!);
Provider.of<Cart>(context, listen: false).removeItem(productId!);
},
background: Container(
margin: const EdgeInsets.symmetric(
vertical: 15.0,horizontal: 4.0,
vertical: 15.0,
horizontal: 4.0,
),
padding: const EdgeInsets.only(right: 20.0),
color: Theme.of(context).errorColor,
alignment: Alignment.centerRight,
child: Icon(Icons.delete , color: Colors.white, size: 40,),
child: Icon(
Icons.delete,
color: Colors.white,
size: 40,
),
),
child: Card(
margin: const EdgeInsets.symmetric(horizontal: 15.0 ,vertical: 4.0),
margin: const EdgeInsets.symmetric(horizontal: 15.0, vertical: 4.0),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: ListTile(
leading: CircleAvatar(child: Padding(
leading: CircleAvatar(
child: Padding(
padding: const EdgeInsets.all(5.0),
child: FittedBox(child: Text('\$ $price')),
)),
Expand Down

0 comments on commit c5d904f

Please sign in to comment.