update info
This commit is contained in:
@@ -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> {
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user