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/core/extensions/int_ext.dart';
|
||||||
import 'package:enaklo_pos/data/models/response/table_model.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/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/assets/assets.gen.dart';
|
||||||
import '../../../core/components/buttons.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(
|
bool _handleScrollNotification(
|
||||||
ScrollNotification notification, String? categoryId) {
|
ScrollNotification notification, String? categoryId) {
|
||||||
// Check if the ScrollController is attached before accessing position
|
|
||||||
if (!scrollController.hasClients) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (notification is ScrollEndNotification &&
|
if (notification is ScrollEndNotification &&
|
||||||
scrollController.position.extentAfter == 0) {
|
scrollController.position.extentAfter == 0) {
|
||||||
context.read<ProductLoaderBloc>().add(
|
context.read<ProductLoaderBloc>().add(
|
||||||
@ -181,39 +163,22 @@ class _HomePageState extends State<HomePage> {
|
|||||||
),
|
),
|
||||||
BlocBuilder<ProductLoaderBloc, ProductLoaderState>(
|
BlocBuilder<ProductLoaderBloc, ProductLoaderState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return NotificationListener<ScrollNotification>(
|
return Expanded(
|
||||||
onNotification: (notification) {
|
|
||||||
return state.maybeWhen(
|
|
||||||
orElse: () => false,
|
|
||||||
loaded: (products, hasReachedMax,
|
|
||||||
currentPage, isLoadingMore) {
|
|
||||||
return _handleScrollNotification(
|
|
||||||
notification, categoryId);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
child: Expanded(
|
|
||||||
child: CategoryTabBar(
|
child: CategoryTabBar(
|
||||||
categories: categories,
|
categories: categories,
|
||||||
tabViews: categories.map((category) {
|
tabViews: categories.map((category) {
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
child: state.maybeWhen(orElse: () {
|
child: state.maybeWhen(orElse: () {
|
||||||
return const Center(
|
return const Center(
|
||||||
child:
|
child: CircularProgressIndicator(),
|
||||||
CircularProgressIndicator(),
|
|
||||||
);
|
);
|
||||||
}, loading: () {
|
}, loading: () {
|
||||||
return const Center(
|
return const Center(
|
||||||
child:
|
child: CircularProgressIndicator(),
|
||||||
CircularProgressIndicator(),
|
|
||||||
);
|
);
|
||||||
}, loaded: (products,
|
}, loaded: (products, hashasReachedMax,
|
||||||
hashasReachedMax,
|
currentPage, isLoadingMore) {
|
||||||
currentPage,
|
if (products.isEmpty) {
|
||||||
isLoadingMore) {
|
|
||||||
final filteredProducts =
|
|
||||||
_filterProducts(products);
|
|
||||||
if (filteredProducts.isEmpty) {
|
|
||||||
return Center(
|
return Center(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
@ -234,9 +199,22 @@ class _HomePageState extends State<HomePage> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return GridView.builder(
|
return NotificationListener<
|
||||||
itemCount:
|
ScrollNotification>(
|
||||||
filteredProducts.length,
|
onNotification: (notification) {
|
||||||
|
return state.maybeWhen(
|
||||||
|
orElse: () => false,
|
||||||
|
loaded: (products,
|
||||||
|
hasReachedMax,
|
||||||
|
currentPage,
|
||||||
|
isLoadingMore) {
|
||||||
|
return _handleScrollNotification(
|
||||||
|
notification, categoryId);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: GridView.builder(
|
||||||
|
itemCount: products.length,
|
||||||
controller: scrollController,
|
controller: scrollController,
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
gridDelegate:
|
gridDelegate:
|
||||||
@ -248,15 +226,15 @@ class _HomePageState extends State<HomePage> {
|
|||||||
),
|
),
|
||||||
itemBuilder: (context, index) =>
|
itemBuilder: (context, index) =>
|
||||||
ProductCard(
|
ProductCard(
|
||||||
data: filteredProducts[index],
|
data: products[index],
|
||||||
onCartButton: () {},
|
onCartButton: () {},
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user