是否可以计算出Firestore文档中有多少张地图?如果是,可以使用ListView.builder吗?

时间:2019-12-09 06:56:16

标签: flutter dart google-cloud-firestore

我的文档有7张地图。我必须使用7个地图创建7个ListTiles。是否需要一一创建listView?还是有什么方法可以创建1个listTile并分配7个地图值?

        StreamBuilder(
            stream: db.getRequirement(uid),
            builder: (context,AsyncSnapshot<RequirementModel> snapshot) {
               return Column(
                  children: <Widget>[
                    pendingWidget(snapshot.data.drivingLicense.status),
                    pendingWidget(snapshot.data.nic.status),
                    pendingWidget(snapshot.data.vehiclePhotos.status),
                    pendingWidget(snapshot.data.vehicleLicense.status),
                  ],
                );
          ),

自定义小部件

 Widget pendingWidget(String status) {
    return ListTile(
        dense: true,
        title: CustomText(
          text:Strings.drivingLicense
        ),
        subtitle: CustomText(
          text: status
        )
    );
 }

1 个答案:

答案 0 :(得分:0)

是的,可以在ListView.builder中完成。实际上,它对于大量的列表视图项目更好,因为它仅构建屏幕上可见的项目。同时,无论是否可见,ListView都会立即构建所有内容。

您可以参考Google的以下链接,以了解如何进行此操作;

https://flutter.dev/docs/cookbook/lists/long-lists