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> {
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ library;
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:worker/features/cart/data/providers/cart_data_providers.dart';
|
||||
import 'package:worker/features/cart/presentation/providers/cart_data_providers.dart';
|
||||
import 'package:worker/features/cart/presentation/providers/cart_state.dart';
|
||||
import 'package:worker/features/products/domain/entities/product.dart';
|
||||
import 'package:worker/features/products/presentation/providers/products_provider.dart';
|
||||
|
||||
@@ -22,9 +22,9 @@ import 'package:worker/features/cart/presentation/providers/cart_state.dart';
|
||||
/// - Quantity controls (-, text field for input, +, unit label)
|
||||
/// - Converted quantity display: "(Quy đổi: X.XX m² = Y viên)"
|
||||
class CartItemWidget extends ConsumerStatefulWidget {
|
||||
final CartItemData item;
|
||||
|
||||
const CartItemWidget({super.key, required this.item});
|
||||
final CartItemData item;
|
||||
|
||||
@override
|
||||
ConsumerState<CartItemWidget> createState() => _CartItemWidgetState();
|
||||
@@ -298,10 +298,10 @@ class _CartItemWidgetState extends ConsumerState<CartItemWidget> {
|
||||
///
|
||||
/// Matches HTML design with 20px size, 6px radius, blue when checked.
|
||||
class _CustomCheckbox extends StatelessWidget {
|
||||
final bool value;
|
||||
final ValueChanged<bool?>? onChanged;
|
||||
|
||||
const _CustomCheckbox({required this.value, this.onChanged});
|
||||
final bool value;
|
||||
final ValueChanged<bool?>? onChanged;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -334,10 +334,10 @@ class _CustomCheckbox extends StatelessWidget {
|
||||
///
|
||||
/// Small button for incrementing/decrementing quantity.
|
||||
class _QuantityButton extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final VoidCallback onPressed;
|
||||
|
||||
const _QuantityButton({required this.icon, required this.onPressed});
|
||||
final IconData icon;
|
||||
final VoidCallback onPressed;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
Reference in New Issue
Block a user