I have a Product class that contains many properties include the name property,
final List<Product> listViewProductsRecordList = snapshot.data;
I have a list view builder which I use to display each product
ListView.builder(
padding: EdgeInsets.zero,
scrollDirection: Axis.horizontal,
itemCount: listViewProductsRecordList.length,
itemBuilder: (context, listViewIndex) {
final listViewProductsRecord = listViewProductsRecordList[listViewIndex];
return Text("${listViewProductsRecord.location.name}");
I get the correct output:
location1
location2
e.t.c
Here come where I am stuck in implementation, I want to display something like this:
location1: 20 Products
location2: 30 Products
What I have tried is the following:
final Map<String,Product> cities = {};
listViewProductsRecord.forEach(
product=>
if(product.location.name==product.location.name){
cities[product.location.city] = product;
}
);
Now I don't know how to proceed from here to achieve the output above without external packages.
#Update
Here is my Product class
class Product {
Product({
this.id,
this.name,
this.description,
this.location,
});
final String id;
final String name;
final String description;
final Location location;
}