update only category have product
This commit is contained in:
@@ -121,6 +121,14 @@ class _PosSaleScreenState extends ConsumerState<PosSaleScreen> {
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: productsList.when(
|
||||
data: (products) {
|
||||
final Set<int> validCategoryIds = products
|
||||
.where((element) =>
|
||||
(element.productType?.toLowerCase().contains('combo') ?? false) ||
|
||||
(element.stocksSumProductStock ?? 0) > 0)
|
||||
.map((e) => e.categoryId)
|
||||
.whereType<int>()
|
||||
.toSet();
|
||||
|
||||
if (!_hasInitializedFilters) {
|
||||
filteredProducts = products.where((product) {
|
||||
// Update: Initial filter allowing Combos
|
||||
@@ -322,7 +330,10 @@ class _PosSaleScreenState extends ConsumerState<PosSaleScreen> {
|
||||
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<CategoryModel>(
|
||||
value: category,
|
||||
child: Text(category.categoryName ?? 'Unnamed'),
|
||||
@@ -538,16 +549,20 @@ class _PosSaleScreenState extends ConsumerState<PosSaleScreen> {
|
||||
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<PosSaleScreen> {
|
||||
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,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user