Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter display data from List once if data is repeated

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try to create a Set from your list, like

var fetchedSet = Set.from(fetchedData);

then iterate like

return Text(
fetchedSet.elementAt(index)
);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading