I am fetching data from a database, and let's say the fetched data then return a list which contains List fetchedData = [2, 4, 6, 1, 2, 5, 2]
, I then want to display the data with a ListView.builder
as so
return ListView.builder(
itemCount: fetchedData.length,
itemBuilder: (context, index) {
return Text(
fetchedData[index],
);
},
),
But the list contains the number 2
more than once, so the number 2 would in this case be displayed three times, but I would only want to display it once, is this possible?
CodePudding user response:
Try to create a Set from your list, like
var fetchedSet = Set.from(fetchedData);
then iterate like
return Text(
fetchedSet.elementAt(index)
);