add cart
This commit is contained in:
@@ -7,7 +7,9 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:worker/core/constants/ui_constants.dart';
|
||||
import 'package:worker/core/router/app_router.dart';
|
||||
import 'package:worker/core/theme/colors.dart';
|
||||
import 'package:worker/features/cart/presentation/providers/cart_provider.dart';
|
||||
import 'package:worker/features/products/presentation/providers/categories_provider.dart';
|
||||
import 'package:worker/features/products/presentation/providers/products_provider.dart';
|
||||
import 'package:worker/features/products/presentation/widgets/category_filter_chips.dart';
|
||||
@@ -31,6 +33,7 @@ class ProductsPage extends ConsumerWidget {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final categoriesAsync = ref.watch(categoriesProvider);
|
||||
final productsAsync = ref.watch(productsProvider);
|
||||
final cartItemCount = ref.watch(cartItemCountProvider);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFF4F6F8), // Match HTML background
|
||||
@@ -47,21 +50,14 @@ class ProductsPage extends ConsumerWidget {
|
||||
actions: [
|
||||
// Cart Icon with Badge
|
||||
IconButton(
|
||||
icon: const Badge(
|
||||
label: Text('3'),
|
||||
icon: Badge(
|
||||
label: Text('$cartItemCount'),
|
||||
backgroundColor: AppColors.danger,
|
||||
textColor: AppColors.white,
|
||||
child: Icon(Icons.shopping_cart_outlined, color: Colors.black,),
|
||||
isLabelVisible: cartItemCount > 0,
|
||||
child: const Icon(Icons.shopping_cart_outlined, color: Colors.black),
|
||||
),
|
||||
onPressed: () {
|
||||
// TODO: Navigate to cart page
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(l10n.cart),
|
||||
duration: const Duration(seconds: 1),
|
||||
),
|
||||
);
|
||||
},
|
||||
onPressed: () => context.go(RouteNames.cart),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
],
|
||||
@@ -102,16 +98,16 @@ class ProductsPage extends ConsumerWidget {
|
||||
context.push('/products/${product.productId}');
|
||||
},
|
||||
onAddToCart: (product) {
|
||||
// TODO: Add to cart logic
|
||||
// Add to cart
|
||||
ref.read(cartProvider.notifier).addToCart(product);
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('${product.name} đã thêm vào giỏ hàng'),
|
||||
duration: const Duration(seconds: 2),
|
||||
action: SnackBarAction(
|
||||
label: 'Xem',
|
||||
onPressed: () {
|
||||
// Navigate to cart
|
||||
},
|
||||
onPressed: () => context.go(RouteNames.cart),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -417,14 +417,14 @@ class _ReviewItem extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
review['name'],
|
||||
review['name']?.toString() ?? '',
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.grey900,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
review['date'],
|
||||
review['date']?.toString() ?? '',
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColors.grey500,
|
||||
@@ -443,7 +443,7 @@ class _ReviewItem extends StatelessWidget {
|
||||
children: List.generate(
|
||||
5,
|
||||
(index) => Icon(
|
||||
index < review['rating']
|
||||
index < (review['rating'] as num? ?? 0).toInt()
|
||||
? Icons.star
|
||||
: Icons.star_border,
|
||||
color: const Color(0xFFffc107),
|
||||
@@ -456,7 +456,7 @@ class _ReviewItem extends StatelessWidget {
|
||||
|
||||
// Review Text
|
||||
Text(
|
||||
review['text'],
|
||||
review['text']?.toString() ?? '',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
height: 1.5,
|
||||
|
||||
Reference in New Issue
Block a user