Flutter Firebase Loop over collection in a document [duplicate]

自作多情 提交于 2021-02-11 14:01:10

问题


I have this path in my Database:

/messages/tT2Q16n1FMZoTNZQOejtWuJdCmD2/ZqihbgR7skcytLAe88fQecmxcIc2-tT2Q16n1FMZoTNZQOejtWuJdCmD2/1579626761580

and from here I have to get content.

I am trying this:

var snapshot = Firestore.instance.collection('messages').document(user.id).snapshots();

but how can I loop over these items and get content from each collection?

And then in my UI I want to print this content message:

              Container(
                child: Text(
                  'Content: ${document['content']}',
                  style: TextStyle(color: primaryColor),
                ),
                alignment: Alignment.centerLeft,
                margin: EdgeInsets.fromLTRB(10.0, 0.0, 0.0, 5.0),
              ),


回答1:


The client-side SDKs for Firestore have no way to request a list of collections. For this reason you'll either need to name your collections in a way that you can embed in your code already, or use one of the Admin SDKs to get a list of collection names and expose that to your client-side code in some way (for example through Cloud Functions).

Also see:

  • Fetching all collections in Firestore
  • Trying to list collection of Firestore Database
  • How to list subcollections in a Cloud Firestore document
  • Using Flutter Firestore plug in, do something for each sub collection in a document


来源:https://stackoverflow.com/questions/59850567/flutter-firebase-loop-over-collection-in-a-document

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!