feat: search product and fix product
This commit is contained in:
@@ -103,7 +103,8 @@ class _HomePageState extends State<HomePage> {
|
||||
}).toList();
|
||||
}
|
||||
|
||||
bool _handleScrollNotification(ScrollNotification notification) {
|
||||
bool _handleScrollNotification(
|
||||
ScrollNotification notification, String? categoryId) {
|
||||
// Check if the ScrollController is attached before accessing position
|
||||
if (!scrollController.hasClients) {
|
||||
return false;
|
||||
@@ -111,9 +112,12 @@ class _HomePageState extends State<HomePage> {
|
||||
|
||||
if (notification is ScrollEndNotification &&
|
||||
scrollController.position.extentAfter == 0) {
|
||||
context
|
||||
.read<ProductLoaderBloc>()
|
||||
.add(const ProductLoaderEvent.loadMore());
|
||||
context.read<ProductLoaderBloc>().add(
|
||||
ProductLoaderEvent.loadMore(
|
||||
categoryId: categoryId,
|
||||
search: searchQuery,
|
||||
),
|
||||
);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -147,42 +151,46 @@ class _HomePageState extends State<HomePage> {
|
||||
flex: 3,
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.topStart,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
HomeTitle(
|
||||
controller: searchController,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
searchQuery = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
BlocBuilder<ProductLoaderBloc, ProductLoaderState>(
|
||||
builder: (context, state) {
|
||||
return NotificationListener<ScrollNotification>(
|
||||
onNotification: (notification) {
|
||||
return state.maybeWhen(
|
||||
orElse: () => false,
|
||||
loaded: (products, hasReachedMax, currentPage,
|
||||
isLoadingMore) {
|
||||
return _handleScrollNotification(
|
||||
notification);
|
||||
},
|
||||
);
|
||||
},
|
||||
child: Expanded(child: BlocBuilder<
|
||||
CategoryLoaderBloc, CategoryLoaderState>(
|
||||
builder: (contextCategory, stateCateogry) {
|
||||
return stateCateogry.maybeWhen(
|
||||
orElse: () => SizedBox.shrink(),
|
||||
loading: () {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
child: BlocBuilder<CategoryLoaderBloc, CategoryLoaderState>(
|
||||
builder: (context, state) {
|
||||
return state.maybeWhen(
|
||||
orElse: () => Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
loaded: (categories, categoryId) => Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
HomeTitle(
|
||||
controller: searchController,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
searchQuery = value;
|
||||
});
|
||||
Future.delayed(Duration(milliseconds: 600), () {
|
||||
context.read<ProductLoaderBloc>().add(
|
||||
ProductLoaderEvent.getProduct(
|
||||
categoryId: categoryId,
|
||||
search: value,
|
||||
),
|
||||
);
|
||||
});
|
||||
},
|
||||
),
|
||||
BlocBuilder<ProductLoaderBloc, ProductLoaderState>(
|
||||
builder: (context, state) {
|
||||
return NotificationListener<ScrollNotification>(
|
||||
onNotification: (notification) {
|
||||
return state.maybeWhen(
|
||||
orElse: () => false,
|
||||
loaded: (products, hasReachedMax,
|
||||
currentPage, isLoadingMore) {
|
||||
return _handleScrollNotification(
|
||||
notification, categoryId);
|
||||
},
|
||||
);
|
||||
},
|
||||
loaded: (categories) {
|
||||
return CategoryTabBar(
|
||||
child: Expanded(
|
||||
child: CategoryTabBar(
|
||||
categories: categories,
|
||||
tabViews: categories.map((category) {
|
||||
return SizedBox(
|
||||
@@ -228,15 +236,15 @@ class _HomePageState extends State<HomePage> {
|
||||
}),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
)),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user