update info

This commit is contained in:
Phuoc Nguyen
2025-11-20 10:12:24 +07:00
parent 54cb7d0fdd
commit 0708ed7d6f
17 changed files with 2144 additions and 161 deletions

View File

@@ -43,12 +43,9 @@ class _CartPageState extends ConsumerState<CartPage> {
});
}
@override
void dispose() {
// Force sync any pending quantity updates before leaving cart page
ref.read(cartProvider.notifier).forceSyncPendingUpdates();
super.dispose();
}
// Note: Sync is handled in PopScope.onPopInvokedWithResult for back navigation
// and in checkout button handler for checkout flow.
// No dispose() method needed - using ref.read() in dispose() is unsafe.
@override
Widget build(BuildContext context) {
@@ -63,13 +60,21 @@ class _CartPageState extends ConsumerState<CartPage> {
final itemCount = cartState.itemCount;
final hasSelection = cartState.selectedCount > 0;
return Scaffold(
backgroundColor: const Color(0xFFF4F6F8),
appBar: AppBar(
leading: IconButton(
icon: const FaIcon(FontAwesomeIcons.arrowLeft, color: Colors.black, size: 20),
onPressed: () => context.pop(),
),
return PopScope(
// Intercept back navigation to sync pending updates
onPopInvokedWithResult: (didPop, result) async {
if (didPop) {
// Sync any pending quantity updates before leaving the page
await ref.read(cartProvider.notifier).forceSyncPendingUpdates();
}
},
child: Scaffold(
backgroundColor: const Color(0xFFF4F6F8),
appBar: AppBar(
leading: IconButton(
icon: const FaIcon(FontAwesomeIcons.arrowLeft, color: Colors.black, size: 20),
onPressed: () => context.pop(),
),
title: Text(
'Giỏ hàng ($itemCount)',
style: const TextStyle(color: Colors.black),
@@ -144,6 +149,7 @@ class _CartPageState extends ConsumerState<CartPage> {
),
],
),
),
);
}