How to access this subcollection?

Viewed 55

enter image description here

I would like to know how I access this subcollection using or Futurebuilder, StreamBuilder. The first error is that it says that the document doesn't have a date, this I solve HashMapOf, but I'm not able to access UserPosts, to show on screen the documents inside UserPosts that would be posts information.

collectionReference =
  firebaseFirestore.collection("posts").doc(authProv.uid).collection('userPosts');

Stream<List<PostModel>> getAllPosts() => collectionReference.snapshots().map(
  (query) => query.docs.map((item) => PostModel.fromMap(item)).toList());

I'm doing like this, and on the page I'm using a ListView builder to get the length and show it on the screen, but it gives this error:

    [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Bad state: field does not exist within the DocumentSnapshotPlatform
E/flutter ( 4336): #0      DocumentSnapshotPlatform.get._findKeyValueInMap
package:cloud_firestore_platform_interface/…/platform_interface/platform_interface_document_snapshot.dart:87
E/flutter ( 4336): #1      DocumentSnapshotPlatform.get._findComponent
package:cloud_firestore_platform_interface/…/platform_interface/platform_interface_document_snapshot.dart:105
E/flutter ( 4336): #2      DocumentSnapshotPlatform.get
package:cloud_firestore_platform_interface/…/platform_interface/platform_interface_document_snapshot.dart:121
E/flutter ( 4336): #3      _JsonDocumentSnapshot.get
package:cloud_firestore/src/document_snapshot.dart:92
E/flutter ( 4336): #4      _JsonDocumentSnapshot.[]
package:cloud_firestore/src/document_snapshot.dart:96
E/flutter ( 4336): #5      new PostModel.fromMap
package:productappwithgetx/…/models/post_model.dart:25
E/flutter ( 4336): #6      PostController.getAllUsers.<anonymous closure>.<anonymous clos
0 Answers
Related