update keep alive filter

This commit is contained in:
Phuoc Nguyen
2025-11-11 15:45:32 +07:00
parent b5afeed534
commit 2f296ad8d3
9 changed files with 96 additions and 64 deletions

View File

@@ -11,6 +11,7 @@ import 'package:worker/core/router/app_router.dart';
import 'package:worker/core/theme/colors.dart';
import 'package:worker/features/cart/presentation/providers/cart_provider.dart';
import 'package:worker/features/products/presentation/providers/categories_provider.dart';
import 'package:worker/features/products/presentation/providers/product_filter_options_provider.dart';
import 'package:worker/features/products/presentation/providers/products_provider.dart';
import 'package:worker/features/products/presentation/widgets/category_filter_chips.dart';
import 'package:worker/features/products/presentation/widgets/product_filter_drawer.dart';
@@ -31,11 +32,14 @@ class ProductsPage extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final l10n = AppLocalizations.of(context)!;
final l10n = AppLocalizations.of(context);
final categoriesAsync = ref.watch(categoriesProvider);
final productsAsync = ref.watch(productsProvider);
final cartItemCount = ref.watch(cartItemCountProvider);
// Preload filter options for better UX when opening filter drawer
ref.watch(productFilterOptionsProvider);
return Scaffold(
backgroundColor: const Color(0xFFF4F6F8), // Match HTML background
endDrawer: const ProductFilterDrawer(),

View File

@@ -90,6 +90,9 @@ class FilterOption {
/// 2. Product Brands
/// 3. Product Attributes
///
/// Memory footprint: ~5-15 KB (negligible)
/// Cache strategy: Keep alive for session duration
///
/// Usage:
/// ```dart
/// final filterOptionsAsync = ref.watch(productFilterOptionsProvider);
@@ -100,7 +103,7 @@ class FilterOption {
/// error: (error, stack) => ErrorWidget(error),
/// );
/// ```
@riverpod
@Riverpod(keepAlive: true)
Future<ProductFilterOptions> productFilterOptions(Ref ref) async {
try {
// Get remote datasource

View File

@@ -15,6 +15,9 @@ part of 'product_filter_options_provider.dart';
/// 2. Product Brands
/// 3. Product Attributes
///
/// Memory footprint: ~5-15 KB (negligible)
/// Cache strategy: Keep alive for session duration
///
/// Usage:
/// ```dart
/// final filterOptionsAsync = ref.watch(productFilterOptionsProvider);
@@ -36,6 +39,9 @@ const productFilterOptionsProvider = ProductFilterOptionsProvider._();
/// 2. Product Brands
/// 3. Product Attributes
///
/// Memory footprint: ~5-15 KB (negligible)
/// Cache strategy: Keep alive for session duration
///
/// Usage:
/// ```dart
/// final filterOptionsAsync = ref.watch(productFilterOptionsProvider);
@@ -64,6 +70,9 @@ final class ProductFilterOptionsProvider
/// 2. Product Brands
/// 3. Product Attributes
///
/// Memory footprint: ~5-15 KB (negligible)
/// Cache strategy: Keep alive for session duration
///
/// Usage:
/// ```dart
/// final filterOptionsAsync = ref.watch(productFilterOptionsProvider);
@@ -80,7 +89,7 @@ final class ProductFilterOptionsProvider
argument: null,
retry: null,
name: r'productFilterOptionsProvider',
isAutoDispose: true,
isAutoDispose: false,
dependencies: null,
$allTransitiveDependencies: null,
);
@@ -101,4 +110,4 @@ final class ProductFilterOptionsProvider
}
String _$productFilterOptionsHash() =>
r'394f47113bc2afeea8a0a4548df826900884644b';
r'253586215f05ca2fd1ccae7922b5925150614af0';