diff --git a/lib/Screens/pos_sale/pos_sale.dart b/lib/Screens/pos_sale/pos_sale.dart index 1be567a..2f6038b 100644 --- a/lib/Screens/pos_sale/pos_sale.dart +++ b/lib/Screens/pos_sale/pos_sale.dart @@ -121,6 +121,14 @@ class _PosSaleScreenState extends ConsumerState { padding: const EdgeInsets.all(16), child: productsList.when( data: (products) { + final Set validCategoryIds = products + .where((element) => + (element.productType?.toLowerCase().contains('combo') ?? false) || + (element.stocksSumProductStock ?? 0) > 0) + .map((e) => e.categoryId) + .whereType() + .toSet(); + if (!_hasInitializedFilters) { filteredProducts = products.where((product) { // Update: Initial filter allowing Combos @@ -322,7 +330,10 @@ class _PosSaleScreenState extends ConsumerState { openMenuIcon: Icon(Icons.keyboard_arrow_up), iconEnabledColor: Colors.grey, ), - items: catSnap.map((category) { + items: catSnap + .where((element) => + validCategoryIds.contains(element.id)) + .map((category) { return DropdownMenuItem( value: category, child: Text(category.categoryName ?? 'Unnamed'), @@ -538,16 +549,20 @@ class _PosSaleScreenState extends ConsumerState { const SizedBox(height: 16), categoryData.when( data: (data) { + final validCategories = data + .where((element) => validCategoryIds.contains(element.id)) + .toList(); return SizedBox( height: 50, child: ListView.builder( - itemCount: data.length + 1, + itemCount: validCategories.length + 1, scrollDirection: Axis.horizontal, itemBuilder: (context, index) { return GestureDetector( onTap: () { setState(() { - selectedCategory = index == 0 ? null : data[index - 1]; + selectedCategory = + index == 0 ? null : validCategories[index - 1]; _applyFilters(); }); }, @@ -556,18 +571,24 @@ class _PosSaleScreenState extends ConsumerState { decoration: BoxDecoration( borderRadius: BorderRadius.circular(5.0), color: (index == 0 && selectedCategory == null) || - (index != 0 && selectedCategory?.id == data[index - 1].id) + (index != 0 && + selectedCategory?.id == + validCategories[index - 1].id) ? kMainColor : kMainColor.withOpacity(0.1), ), padding: const EdgeInsets.all(10), child: Center( child: Text( - index == 0 ? lang.S.of(context).all : data[index - 1].categoryName ?? '', + index == 0 + ? lang.S.of(context).all + : validCategories[index - 1].categoryName ?? '', style: TextStyle( fontSize: 14, color: (index == 0 && selectedCategory == null) || - (index != 0 && selectedCategory?.id == data[index - 1].id) + (index != 0 && + selectedCategory?.id == + validCategories[index - 1].id) ? Colors.white : kMainColor, ),