Flutter Firestore用单个文档对象列表填充ListView

时间:2018-12-11 06:59:38

标签: dart flutter google-cloud-firestore

我到处都是,却找不到任何资源。使用Flutter,我尝试使用地图/对象在Firestore中使用单个文档来填充Future Listview构建器。我当前在Firestore中的结构看起来像这样

 (Collection)Restaurants
      (Document)California
           (Map)Locations
                (String) A0 = Los Angeles
                (String) A1 = LA Restaurant 1
                (String) A2 = LA Restaurant 2
                (String) A3 = LA Restaurant 3
                (String) B0 = San Diego
                (String) B1 = SD Restaurant 1
                (String) B2 = SD Restaurant 2
                (String) B3 = SD Restaurant 3

我发现的每个资源都会将每个Map对象放在他们自己的文档中,然后整体检索集合以填充列表。是否可以使用单个文档中的Map来执行相同操作?如果是这样,您将如何检索它?

 body: new Container(
    child: FutureBuilder(
        future: getList(),
        builder: (_, snapshot){
          if(snapshot.connectionState == ConnectionState.waiting){
            return Center(
              child: CircularProgressIndicator(),
            );
          }else{
            return ListView.builder(
                itemCount: snapshot.data["California.Locations"].length,
                itemBuilder: (_, index){

                  if(snapshot.data["California.Location"] == "A0"){
                    return ListTile(
                      title: new Center(child: Text(snapshot.data[index].data,
                        style: TextStyle(fontSize: 25.0),),),
                    );
                  }else if(snapshot.data["California.Location"] != "A0") {
                    return ListTile(
                      title: Text(snapshot.data[index].data["name"],
                        style: TextStyle(
                            fontWeight: FontWeight.w500,
                            color: Colors.black),
                      ),
                      onTap: (){
                        Navigator.push(
                            context,
                            MaterialPageRoute(builder: (context)=> RestaurantDetail())
                        );
                      },
                    );
                  }
               });
         }}),
       ),

我的if语句是将LA和San Diego作为列表的标题。

0 个答案:

没有答案