update only category have product
This commit is contained in:
@@ -121,6 +121,14 @@ class _PosSaleScreenState extends ConsumerState<PosSaleScreen> {
|
|||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
child: productsList.when(
|
child: productsList.when(
|
||||||
data: (products) {
|
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) {
|
if (!_hasInitializedFilters) {
|
||||||
filteredProducts = products.where((product) {
|
filteredProducts = products.where((product) {
|
||||||
// Update: Initial filter allowing Combos
|
// Update: Initial filter allowing Combos
|
||||||
@@ -322,7 +330,10 @@ class _PosSaleScreenState extends ConsumerState<PosSaleScreen> {
|
|||||||
openMenuIcon: Icon(Icons.keyboard_arrow_up),
|
openMenuIcon: Icon(Icons.keyboard_arrow_up),
|
||||||
iconEnabledColor: Colors.grey,
|
iconEnabledColor: Colors.grey,
|
||||||
),
|
),
|
||||||
items: catSnap.map((category) {
|
items: catSnap
|
||||||
|
.where((element) =>
|
||||||
|
validCategoryIds.contains(element.id))
|
||||||
|
.map((category) {
|
||||||
return DropdownMenuItem<CategoryModel>(
|
return DropdownMenuItem<CategoryModel>(
|
||||||
value: category,
|
value: category,
|
||||||
child: Text(category.categoryName ?? 'Unnamed'),
|
child: Text(category.categoryName ?? 'Unnamed'),
|
||||||
@@ -538,16 +549,20 @@ class _PosSaleScreenState extends ConsumerState<PosSaleScreen> {
|
|||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
categoryData.when(
|
categoryData.when(
|
||||||
data: (data) {
|
data: (data) {
|
||||||
|
final validCategories = data
|
||||||
|
.where((element) => validCategoryIds.contains(element.id))
|
||||||
|
.toList();
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
height: 50,
|
height: 50,
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
itemCount: data.length + 1,
|
itemCount: validCategories.length + 1,
|
||||||
scrollDirection: Axis.horizontal,
|
scrollDirection: Axis.horizontal,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
selectedCategory = index == 0 ? null : data[index - 1];
|
selectedCategory =
|
||||||
|
index == 0 ? null : validCategories[index - 1];
|
||||||
_applyFilters();
|
_applyFilters();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -556,18 +571,24 @@ class _PosSaleScreenState extends ConsumerState<PosSaleScreen> {
|
|||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(5.0),
|
borderRadius: BorderRadius.circular(5.0),
|
||||||
color: (index == 0 && selectedCategory == null) ||
|
color: (index == 0 && selectedCategory == null) ||
|
||||||
(index != 0 && selectedCategory?.id == data[index - 1].id)
|
(index != 0 &&
|
||||||
|
selectedCategory?.id ==
|
||||||
|
validCategories[index - 1].id)
|
||||||
? kMainColor
|
? kMainColor
|
||||||
: kMainColor.withOpacity(0.1),
|
: kMainColor.withOpacity(0.1),
|
||||||
),
|
),
|
||||||
padding: const EdgeInsets.all(10),
|
padding: const EdgeInsets.all(10),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Text(
|
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(
|
style: TextStyle(
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
color: (index == 0 && selectedCategory == null) ||
|
color: (index == 0 && selectedCategory == null) ||
|
||||||
(index != 0 && selectedCategory?.id == data[index - 1].id)
|
(index != 0 &&
|
||||||
|
selectedCategory?.id ==
|
||||||
|
validCategories[index - 1].id)
|
||||||
? Colors.white
|
? Colors.white
|
||||||
: kMainColor,
|
: kMainColor,
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user