-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
task: refactoring cart into buildCart
- Loading branch information
Showing
2 changed files
with
139 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import 'package:flutter/material.dart'; | ||
import '../../../constants/colors.dart'; | ||
|
||
Dismissible buildCart( | ||
void Function(String prodId) removeFromCart, | ||
item, | ||
BuildContext context, | ||
void Function(String id) increaseQuantity, | ||
void Function(String id) reduceQuantity, | ||
) { | ||
return Dismissible( | ||
onDismissed: (direction) => removeFromCart(item.prodId), | ||
direction: DismissDirection.endToStart, | ||
background: Container( | ||
height: 115, | ||
decoration: BoxDecoration( | ||
borderRadius: BorderRadius.circular(10), | ||
color: Colors.red, | ||
), | ||
alignment: Alignment.centerRight, | ||
padding: const EdgeInsets.only(right: 20), | ||
child: const Icon( | ||
Icons.delete_forever, | ||
color: Colors.white, | ||
size: 40, | ||
), | ||
), | ||
confirmDismiss: (direction) => showDialog( | ||
context: context, | ||
builder: (context) => AlertDialog( | ||
title: Text('Remove ${item.prodName}'), | ||
content: Text( | ||
'Are you sure you want to remove ${item.prodName} from cart?', | ||
), | ||
actions: [ | ||
ElevatedButton( | ||
style: ElevatedButton.styleFrom( | ||
primary: primaryColor, | ||
shape: RoundedRectangleBorder( | ||
borderRadius: BorderRadius.circular(10), | ||
), | ||
), | ||
onPressed: () => Navigator.of(context).pop(true), | ||
child: const Text( | ||
'Yes', | ||
style: TextStyle( | ||
color: Colors.white, | ||
), | ||
), | ||
), | ||
ElevatedButton( | ||
style: ElevatedButton.styleFrom( | ||
primary: primaryColor, | ||
shape: RoundedRectangleBorder( | ||
borderRadius: BorderRadius.circular(10), | ||
), | ||
), | ||
onPressed: () => Navigator.of(context).pop(false), | ||
child: const Text( | ||
'Cancel', | ||
style: TextStyle( | ||
color: Colors.white, | ||
), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
key: ValueKey(item.id), | ||
child: Card( | ||
elevation: 3, | ||
child: ListTile( | ||
contentPadding: const EdgeInsets.only( | ||
left: 10, | ||
right: 10, | ||
top: 5, | ||
), | ||
leading: CircleAvatar( | ||
backgroundColor: primaryColor, | ||
backgroundImage: NetworkImage(item.prodImgUrl), | ||
), | ||
title: Text( | ||
item.prodName, | ||
style: const TextStyle( | ||
fontSize: 16, | ||
), | ||
), | ||
subtitle: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Text('\$${item.totalPrice}'), | ||
const SizedBox(height: 5), | ||
Row( | ||
children: [ | ||
GestureDetector( | ||
onTap: () => increaseQuantity(item.id), | ||
child: const Icon( | ||
Icons.add, | ||
color: primaryColor, | ||
), | ||
), | ||
const SizedBox(width: 10), | ||
Text( | ||
item.quantity.toString(), | ||
style: const TextStyle( | ||
fontWeight: FontWeight.bold, | ||
fontSize: 18, | ||
), | ||
), | ||
const SizedBox(width: 10), | ||
GestureDetector( | ||
onTap: () => reduceQuantity(item.id), | ||
child: const Icon( | ||
Icons.remove, | ||
color: primaryColor, | ||
), | ||
), | ||
], | ||
), | ||
], | ||
), | ||
trailing: IconButton( | ||
onPressed: () => removeFromCart(item.prodId), | ||
icon: const Icon( | ||
Icons.delete_forever, | ||
color: primaryColor, | ||
), | ||
), | ||
), | ||
), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters