使用Flutter从Firestore提取特定数据

时间:2020-07-01 06:02:46

标签: flutter google-cloud-firestore

我将Firestore用作Flutter应用程序的数据库。我以以下方式存储数据:

My FFirestore Database Image

我想基于文档ID(这是当前登录用户的ID)获取商店的数据。我正在使用以下代码,但无法获取特定数据。 并使用流构建器来显示数据。

StreamBuilder(
          stream: Firestore.instance
              .collection('Shops')
              .document(user.uid)
              .snapshots(),
          builder: (context, snapshot) {
            print(snapshot.hasData);
            if (snapshot.hasData) {
              return ListView.builder(
                  physics: NeverScrollableScrollPhysics(),
                  shrinkWrap: true,
                  scrollDirection: Axis.vertical,
                  itemCount: snapshot.data.documents.length,
                  itemBuilder: (context, i) {
                    return SingleChildScrollView(
                      child: Column(children: <Widget>[
                        _buildRow(context, snapshot, i),
                        SizedBox(
                          height: 20,
                        ),
                        _buildShopDetails(context, snapshot, i),
                        _buildReviewsRatingCard(snapshot, i),
                      ]),
                    );
                  });
            } else {
              return CircularProgressIndicator();
            }
          },
        ),

请帮助我解决问题。

0 个答案:

没有答案