how to return only productlist(List<ProductModel> products) rather than returning widget
Closed this issue · 1 comments
SriRamGovardhanam commented
Hi Ashish,
Thanks for sharing your work, backend structure is really great.
is there any way that i can return productlist(List products) without returning any widget?
every time I use BlocConsumer or Builder its asking for a Widget to return from dataWidget, how can i simply return the list
can u suggest me some modifications for it
cubit: allProductsCubit,
listener:
(BuildContext context, ResultState<List<ProductModel>> state) {},
builder: (BuildContext context, ResultState<List<ProductModel>> state) {
return ResultStateBuilder(
state: state,
loadingWidget: (bool isReloading) {
return Center(
child: CommonAppLoader(),
);
},
errorWidget: (String error) {
return Container();
},
dataWidget: (List<ProductModel> value) {
return dataWidget(value); //only returns widget here
},
);
},
),
I got that there is something I need to change at result_state, cannot understand what to change
Response would be much appreciated!
SriRamGovardhanam commented
I got to know about that using
fetchProduct([String condition]) async {
try {
if (condition == null) {
documents = await _firebaseRepo.getAllProducts();
} else {
documents = await _firebaseRepo.getAllProductsData(condition);
}
products = List<Product>.generate(
documents.length, (index) => Product.fromJson(documents[index]));
List.generate(products.length, (index) {
print(products[index].name);
});
print(products.length);
print(products);
return products.toSet().toList();
} catch (e) {
return e.toString();
}
}