update favorite, chat

This commit is contained in:
Phuoc Nguyen
2025-11-03 17:05:47 +07:00
parent 988216b151
commit b3d7637760
6 changed files with 530 additions and 81 deletions

View File

@@ -19,10 +19,6 @@ import 'package:worker/generated/l10n/app_localizations.dart';
/// Displays product information in a card format.
/// Includes image, name, price, stock status, favorite toggle, and add to cart button.
class ProductCard extends ConsumerWidget {
final Product product;
final VoidCallback? onTap;
final VoidCallback? onAddToCart;
const ProductCard({
super.key,
required this.product,
@@ -30,6 +26,10 @@ class ProductCard extends ConsumerWidget {
this.onAddToCart,
});
final Product product;
final VoidCallback? onTap;
final VoidCallback? onAddToCart;
String _formatPrice(double price) {
final formatter = NumberFormat('#,###', 'vi_VN');
return '${formatter.format(price)}đ';
@@ -37,7 +37,7 @@ class ProductCard extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final l10n = AppLocalizations.of(context)!;
final l10n = AppLocalizations.of(context);
final isFavorited = ref.watch(isFavoriteProvider(product.productId));
return Card(
@@ -142,23 +142,29 @@ class ProductCard extends ConsumerWidget {
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: () {
ref
onTap: () async {
// Capture current state before toggle
final wasfavorited = isFavorited;
// Toggle favorite
await ref
.read(favoritesProvider.notifier)
.toggleFavorite(product.productId);
// Show feedback
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
isFavorited
? 'Đã xóa khỏi yêu thích'
: 'Đã thêm vào yêu thích',
// Show feedback with correct message
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
wasfavorited
? 'Đã xóa khỏi yêu thích'
: 'Đã thêm vào yêu thích',
),
duration: const Duration(seconds: 1),
behavior: SnackBarBehavior.floating,
),
duration: const Duration(seconds: 1),
behavior: SnackBarBehavior.floating,
),
);
);
}
},
borderRadius: BorderRadius.circular(20),
child: Container(
@@ -169,7 +175,7 @@ class ProductCard extends ConsumerWidget {
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.15),
color: Colors.black.withValues(alpha: 0.15),
blurRadius: 6,
offset: const Offset(0, 2),
),