update products

This commit is contained in:
Phuoc Nguyen
2025-10-15 16:58:20 +07:00
parent f6d2971224
commit 4038f8e8a6
17 changed files with 1172 additions and 314 deletions

View File

@@ -25,6 +25,13 @@ class _ProductsPageState extends ConsumerState<ProductsPage> {
final selectedCategory = ref.watch(product_providers.selectedCategoryProvider);
final productsAsync = ref.watch(productsProvider);
// Debug: Log product loading state
productsAsync.whenOrNull(
data: (products) => debugPrint('Products loaded: ${products.length} items'),
loading: () => debugPrint('Products loading...'),
error: (error, stack) => debugPrint('Products error: $error'),
);
// Get filtered products from the provider
final filteredProducts = productsAsync.when(
data: (products) => products,
@@ -168,12 +175,14 @@ class _ProductsPageState extends ConsumerState<ProductsPage> {
),
),
),
body: RefreshIndicator(
onRefresh: () async {
await ref.refresh(productsProvider.future);
await ref.refresh(categoriesProvider.future);
},
child: Column(
body: productsAsync.when(
data: (products) => RefreshIndicator(
onRefresh: () async {
// Force sync with API
await ref.read(productsProvider.notifier).syncProducts();
await ref.refresh(categoriesProvider.future);
},
child: Column(
children: [
// Results count
if (filteredProducts.isNotEmpty)
@@ -194,6 +203,23 @@ class _ProductsPageState extends ConsumerState<ProductsPage> {
),
],
),
),
loading: () => const Center(child: CircularProgressIndicator()),
error: (error, stack) => Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.error_outline, size: 48, color: Colors.red),
const SizedBox(height: 16),
Text('Error loading products: $error'),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () => ref.refresh(productsProvider),
child: const Text('Retry'),
),
],
),
),
),
);
}