问题
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