fix force close at home
This commit is contained in:
parent
78914d7140
commit
f18a70b312
@ -14,7 +14,6 @@ import 'package:enaklo_pos/core/extensions/build_context_ext.dart';
|
||||
import 'package:enaklo_pos/core/extensions/int_ext.dart';
|
||||
import 'package:enaklo_pos/data/models/response/table_model.dart';
|
||||
import 'package:enaklo_pos/presentation/home/pages/confirm_payment_page.dart';
|
||||
import 'package:enaklo_pos/data/models/response/product_response_model.dart';
|
||||
|
||||
import '../../../core/assets/assets.gen.dart';
|
||||
import '../../../core/components/buttons.dart';
|
||||
@ -94,25 +93,8 @@ class _HomePageState extends State<HomePage> {
|
||||
});
|
||||
}
|
||||
|
||||
List<Product> _filterProducts(List<Product> products) {
|
||||
if (searchQuery.isEmpty) {
|
||||
return products;
|
||||
}
|
||||
|
||||
return products.where((product) {
|
||||
final productName = product.name?.toLowerCase() ?? '';
|
||||
final queryLower = searchQuery.toLowerCase();
|
||||
return productName.contains(queryLower);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
bool _handleScrollNotification(
|
||||
ScrollNotification notification, String? categoryId) {
|
||||
// Check if the ScrollController is attached before accessing position
|
||||
if (!scrollController.hasClients) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (notification is ScrollEndNotification &&
|
||||
scrollController.position.extentAfter == 0) {
|
||||
context.read<ProductLoaderBloc>().add(
|
||||
@ -181,39 +163,22 @@ class _HomePageState extends State<HomePage> {
|
||||
),
|
||||
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);
|
||||
},
|
||||
);
|
||||
},
|
||||
child: Expanded(
|
||||
return Expanded(
|
||||
child: CategoryTabBar(
|
||||
categories: categories,
|
||||
tabViews: categories.map((category) {
|
||||
return SizedBox(
|
||||
child: state.maybeWhen(orElse: () {
|
||||
return const Center(
|
||||
child:
|
||||
CircularProgressIndicator(),
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}, loading: () {
|
||||
return const Center(
|
||||
child:
|
||||
CircularProgressIndicator(),
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}, loaded: (products,
|
||||
hashasReachedMax,
|
||||
currentPage,
|
||||
isLoadingMore) {
|
||||
final filteredProducts =
|
||||
_filterProducts(products);
|
||||
if (filteredProducts.isEmpty) {
|
||||
}, loaded: (products, hashasReachedMax,
|
||||
currentPage, isLoadingMore) {
|
||||
if (products.isEmpty) {
|
||||
return Center(
|
||||
child: Column(
|
||||
children: [
|
||||
@ -234,9 +199,22 @@ class _HomePageState extends State<HomePage> {
|
||||
),
|
||||
);
|
||||
}
|
||||
return GridView.builder(
|
||||
itemCount:
|
||||
filteredProducts.length,
|
||||
return NotificationListener<
|
||||
ScrollNotification>(
|
||||
onNotification: (notification) {
|
||||
return state.maybeWhen(
|
||||
orElse: () => false,
|
||||
loaded: (products,
|
||||
hasReachedMax,
|
||||
currentPage,
|
||||
isLoadingMore) {
|
||||
return _handleScrollNotification(
|
||||
notification, categoryId);
|
||||
},
|
||||
);
|
||||
},
|
||||
child: GridView.builder(
|
||||
itemCount: products.length,
|
||||
controller: scrollController,
|
||||
padding: const EdgeInsets.all(16),
|
||||
gridDelegate:
|
||||
@ -248,15 +226,15 @@ class _HomePageState extends State<HomePage> {
|
||||
),
|
||||
itemBuilder: (context, index) =>
|
||||
ProductCard(
|
||||
data: filteredProducts[index],
|
||||
data: products[index],
|
||||
onCartButton: () {},
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user