I know this question have been asked by many, its related to index of list to be viewd in grid view. The issue of mine is combining GridView.count()
with Obx()
using Getx
and mapping through the resault which is RxList<Product>
bindstream with query result.
here is my code:
Obx(() {
return GridView.count(
scrollDirection: Axis.vertical,
primary: false,
crossAxisCount:
controller.filteredProducts.isEmpty ? 1 : 4,
childAspectRatio: (1.9 / 1),
children: controller.filteredProducts.isEmpty
? const [
Center(
child: Text(
"No Products! Try starting to type name of Product"),
),
]
: controller.filteredProducts
.map(
(p) => _item(
title: p.name,
price: p.getPrice().toString(),
item: p.stockCount().toString(),
),
)
.toList(),
);
}),
in the above code there is no space to control index of list to solve the the error
RangeError (index): Invalid value: Valid value range is empty: 0
in the background, I'm trying to update list of products upon searchfield instantly by starting to type the name. When I print the list of filteredProducts
it shows the right results but in the view it shows this error when I start typing the product name.