From e585cf4292e120c287561062af03aa9fbf624b98 Mon Sep 17 00:00:00 2001 From: efrilm Date: Thu, 23 Oct 2025 20:11:16 +0700 Subject: [PATCH] update --- .../category/category_local_datasource.dart | 2 +- .../category_loader/category_loader_bloc.dart | 10 ++-- .../home/widgets/product_card.dart | 52 ++++++++++++------- pubspec.yaml | 2 +- 4 files changed, 40 insertions(+), 26 deletions(-) diff --git a/lib/data/datasources/category/category_local_datasource.dart b/lib/data/datasources/category/category_local_datasource.dart index e9e8846..004cbb0 100644 --- a/lib/data/datasources/category/category_local_datasource.dart +++ b/lib/data/datasources/category/category_local_datasource.dart @@ -128,7 +128,7 @@ class CategoryLocalDatasource { whereArgs.add('%$search%'); } - query += ' ORDER BY name ASC'; + // query += ' ORDER BY name ASC'; if (limit > 0) { query += ' LIMIT ?'; diff --git a/lib/presentation/home/bloc/category_loader/category_loader_bloc.dart b/lib/presentation/home/bloc/category_loader/category_loader_bloc.dart index 4721532..a9b2dba 100644 --- a/lib/presentation/home/bloc/category_loader/category_loader_bloc.dart +++ b/lib/presentation/home/bloc/category_loader/category_loader_bloc.dart @@ -47,7 +47,7 @@ class CategoryLoaderBloc final result = await _categoryRepository.getCategories( page: 1, - limit: 10, + limit: 50, isActive: event.isActive, search: event.search, forceRemote: event.forceRemote, @@ -59,11 +59,13 @@ class CategoryLoaderBloc emit(CategoryLoaderState.error(failure)); }, (response) async { - final categories = response.data.categories; - categories.insert(0, CategoryModel.all()); + final categories = [ + CategoryModel.all(), + ...response.data.categories, + ]; final totalPages = response.data.totalPages; - final hasReachedMax = categories.length < 10 || 1 >= totalPages; + final hasReachedMax = categories.length < 50 || 1 >= totalPages; log('✅ Categories loaded: ${categories.length}, hasReachedMax: $hasReachedMax'); diff --git a/lib/presentation/home/widgets/product_card.dart b/lib/presentation/home/widgets/product_card.dart index 399c2ab..6e68e5c 100644 --- a/lib/presentation/home/widgets/product_card.dart +++ b/lib/presentation/home/widgets/product_card.dart @@ -54,24 +54,8 @@ class ProductCard extends StatelessWidget { children: [ ClipRRect( borderRadius: BorderRadius.all(Radius.circular(8.0)), - child: CachedNetworkImage( - imageUrl: (data.imageUrl ?? "").contains('http') - ? data.imageUrl! - : '${Variables.baseUrl}/${data.imageUrl}', - fit: BoxFit.cover, - width: double.infinity, - height: 120, - memCacheHeight: 120, - memCacheWidth: 120, - errorWidget: (context, url, error) { - FirebaseCrashlytics.instance.recordError( - error, - StackTrace.current, - reason: - 'Failed to load image from: $url, productId: ${data.id}, productName: ${data.name}', - fatal: false, - ); - return Container( + child: data.imageUrl == "" + ? Container( width: double.infinity, height: 120, decoration: BoxDecoration( @@ -81,8 +65,36 @@ class ProductCard extends StatelessWidget { Icons.image, color: AppColors.grey, ), - ); - }), + ) + : CachedNetworkImage( + imageUrl: (data.imageUrl ?? "").contains('http') + ? data.imageUrl! + : '${Variables.baseUrl}/${data.imageUrl}', + fit: BoxFit.cover, + width: double.infinity, + height: 120, + memCacheHeight: 120, + memCacheWidth: 120, + errorWidget: (context, url, error) { + FirebaseCrashlytics.instance.recordError( + error, + StackTrace.current, + reason: + 'Failed to load image from: $url, productId: ${data.id}, productName: ${data.name}, dataUrl: ${data.imageUrl}', + fatal: false, + ); + return Container( + width: double.infinity, + height: 120, + decoration: BoxDecoration( + color: AppColors.disabled.withOpacity(0.4), + ), + child: const Icon( + Icons.image, + color: AppColors.grey, + ), + ); + }), ), const Spacer(), Text( diff --git a/pubspec.yaml b/pubspec.yaml index ff47ccb..7382501 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.2+6 +version: 1.0.2+7 environment: sdk: ">=3.2.4 <4.0.0"