create order
This commit is contained in:
@@ -66,6 +66,7 @@ class _ProductDetailPageState extends ConsumerState<ProductDetailPage> {
|
||||
// Show feedback
|
||||
final isFavorite = ref.read(isFavoriteProvider(widget.productId));
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
@@ -117,6 +118,7 @@ class _ProductDetailPageState extends ConsumerState<ProductDetailPage> {
|
||||
title: const Text('Chia sẻ qua tin nhắn'),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Đang phát triển tính năng chat'),
|
||||
|
||||
@@ -34,7 +34,6 @@ class ProductsPage extends ConsumerWidget {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final productsAsync = ref.watch(productsProvider);
|
||||
final cartItemCount = ref.watch(cartItemCountProvider);
|
||||
|
||||
// Preload filter options for better UX when opening filter drawer
|
||||
ref.watch(productFilterOptionsProvider);
|
||||
@@ -53,16 +52,21 @@ class ProductsPage extends ConsumerWidget {
|
||||
foregroundColor: AppColors.grey900,
|
||||
centerTitle: false,
|
||||
actions: [
|
||||
// Cart Icon with Badge
|
||||
IconButton(
|
||||
icon: Badge(
|
||||
label: Text('$cartItemCount'),
|
||||
backgroundColor: AppColors.danger,
|
||||
textColor: AppColors.white,
|
||||
isLabelVisible: cartItemCount > 0,
|
||||
child: const FaIcon(FontAwesomeIcons.cartShopping, color: Colors.black, size: 20),
|
||||
),
|
||||
onPressed: () => context.push(RouteNames.cart),
|
||||
// Cart Icon with Badge (extracted to Consumer to prevent full page rebuild)
|
||||
Consumer(
|
||||
builder: (context, ref, child) {
|
||||
final cartItemCount = ref.watch(cartItemCountProvider);
|
||||
return IconButton(
|
||||
icon: Badge(
|
||||
label: Text('$cartItemCount'),
|
||||
backgroundColor: AppColors.danger,
|
||||
textColor: AppColors.white,
|
||||
isLabelVisible: cartItemCount > 0,
|
||||
child: const FaIcon(FontAwesomeIcons.cartShopping, color: Colors.black, size: 20),
|
||||
),
|
||||
onPressed: () => context.push(RouteNames.cart),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
],
|
||||
@@ -129,13 +133,29 @@ class ProductsPage extends ConsumerWidget {
|
||||
// Add to cart
|
||||
ref.read(cartProvider.notifier).addToCart(product);
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
// Show SnackBar with manual dismissal
|
||||
final messenger = ScaffoldMessenger.of(context)
|
||||
..clearSnackBars();
|
||||
|
||||
final controller = messenger.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('${product.name} đã thêm vào giỏ hàng'),
|
||||
duration: const Duration(seconds: 2),
|
||||
action: SnackBarAction(label: 'Xem', onPressed: () => context.go(RouteNames.cart)),
|
||||
duration: const Duration(days: 365), // Prevent auto-dismiss
|
||||
behavior: SnackBarBehavior.floating,
|
||||
action: SnackBarAction(
|
||||
label: 'Xem',
|
||||
onPressed: () {
|
||||
messenger.hideCurrentSnackBar();
|
||||
context.go(RouteNames.cart);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Manually dismiss after 2 seconds
|
||||
Future.delayed(const Duration(seconds: 2), () {
|
||||
controller.close();
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user