首页 > 解决方案 > 如何在flutter firebase中使用子集合填充扩展列表视图

问题描述

我在颤振中有一个类别页面,其中有一个带有类别名称的可扩展磁贴,每个类别都有多个子类别。我的firebase设置如下 Firebase 类别

在此处输入图像描述

我的代码如下

Container(
        padding: EdgeInsets.all(10.0),
        child: FutureBuilder(
          future: getcat(),
          builder: (context, AsyncSnapshot<QuerySnapshot> snapshot){
            if (snapshot.connectionState == ConnectionState.done){
              return ListView.builder(
                  shrinkWrap: true,
                  itemCount: snapshot.data.docs.length,
                  itemBuilder: (BuildContext context, int index){
                    return ExpansionTile(
                      title: Text(snapshot.data.docs[index].data()["Name"]),
                      children: [
                       //List View nested
                        FutureBuilder(future: getcat(),
                            builder: (context, AsyncSnapshot<QuerySnapshot> snapshot){
                              if (snapshot.connectionState == ConnectionState.done){
                                return ListView.builder(
                                    shrinkWrap: true,
                                    itemCount: snapshot.data.docs.length,
                                    itemBuilder: (BuildContext context, int index){
                                      return ListTile(
                                        title: Text(snapshot.data.docs[index].data()["Name"]),
                                      );
                                    }
                                );
                              }else if(snapshot.connectionState == ConnectionState.none){
                                return Text("No data");

                              }
                              return CircularProgressIndicator();
                            }
                        )


                      ],

                    );
                  }
              );
            }else if(snapshot.connectionState == ConnectionState.none){
              return Text("No data");

            }
            return CircularProgressIndicator();
          },
        ),


      ),

    );
  }
}
Future<QuerySnapshot> getcat() {
  return fb.collection("Categories").get();
}

如何在扩展磁贴的子项列表中获取所有子集合名称的列表

标签: firebaseflutter

解决方案


推荐阅读