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