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

Using Wrap, and Chips inside of ListView

I am trying to have a list of data that is being returned by firebase basically represented on screen as a collection of filterable tags. The problem is when using wrap inside of my list view I am still get just a horizontal list of chips.

Light Grey is what I am after, dark grey is what is being returned

FutureBuilder _buildSubCategories() {
    return FutureBuilder(
        future: cats
            .doc(widget.catId)
            .collection('sub-categories')
            .orderBy('name')
            .get(),
        builder: (ctx, AsyncSnapshot snapshot) {
          if (!snapshot.hasData) {
            return const Center(child: CircularProgressIndicator.adaptive());
          } else {
            return ListView.builder(
                itemCount: snapshot.data.docs.length,
                physics: const NeverScrollableScrollPhysics(),
                scrollDirection: Axis.horizontal,
                itemBuilder: (ctx, idx) {
                  // DocumentSnapshot cat = snapshot.data.docs[index];
                  return Wrap(
                    children: snapshot.data.docs
                        .map((item) => ActionChip(
                              label: Text(item['name']),
                            ))
                        .toList()
                        .cast<Widget>(),
                  );
                });
          }
        });
  }

enter image description here

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 :

You do not need to use list view for that. You could simply use Wrap. Wrap widget pushes the overflown widget to next line

Example:

FutureBuilder _buildSubCategories() {
    return FutureBuilder(
        future: cats
            .doc(widget.catId)
            .collection('sub-categories')
            .orderBy('name')
            .get(),
        builder: (ctx, AsyncSnapshot snapshot) {
          if (!snapshot.hasData) {
            return const Center(child: CircularProgressIndicator.adaptive());
          } else {
            return Wrap(
                    children: snapshot.data.docs
                        .map((item) => ActionChip(
                              label: Text(item['name']),
                            ))
                        .toList()
                        .cast<Widget>(),
                  );
          }
        });
  }
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