简体   繁体   English

在 ListView 中使用 Wrap 和 Chips

[英]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.我试图让 firebase 返回的数据列表基本上在屏幕上表示为可过滤标签的集合。 The problem is when using wrap inside of my list view I am still get just a horizontal list of chips.问题是在我的列表视图中使用 wrap 时,我仍然只得到一个水平的芯片列表。

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>(),
                  );
                });
          }
        });
  }

在此处输入图像描述

You do not need to use list view for that.您不需要为此使用列表视图。 You could simply use Wrap .您可以简单地使用Wrap Wrap widget pushes the overflown widget to next line Wrap 小部件将溢出的小部件推送到下一行

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>(); ); } }); }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter 在firebase中使用选择芯片过滤阵列 - Flutter using choice chips to filter array in firebase Flutter 中 ListView 内的 FirestoreListView - FirestoreListView inside ListView in Flutter 如何在 Flutter 中用 Column 或 ListView class 包装 StreamBuilder class? - How to wrap a StreamBuilder class with a Column or ListView class in Flutter? FLutter 如果在 ListView 中继承了 Listview 生成器,则 LazyLoading 不起作用 - FLutter LazyLoading not working if Listview builder is inherited inside ListView 在 StreamBuilder 中使用 FutureBuilder - Using FutureBuilder inside StreamBuilder 使用 Firebase 中的数据创建 Listview - Create Listview using data from Firebase 如何使用 AWS appsync 将现有的 REST API 包装到 graphQL API 中? - How can I wrap an existing REST API into graphQL API using AWS appsync? 无法运行 Echo Bot Google Messaging API。不回复“card”、“carousel”、“chips”字符串 - Unable to run Echo Bot Google Messaging API. Doesn't reply to "card", "carousel", "chips" strings Azure Function TextWriter stream 附加到文件而不是覆盖 - 我需要用 using 语句包装吗? - Azure Function TextWriter stream is appending to file and not overwriting - do I need to wrap in a using statement? 在Flutter中使用带有FireBase数据的StreamBuilder时,如何将ListView替换为GroupedListView? - How to replace ListView with GroupedListView while using StreamBuilder with FireBase data in Flutter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM