Retrieve stream value then call another stream based on the previous value using Flutter with firestore

Viewed 62

This is the  main firestore Structure this is followings collection this is posts collection

**This posts collection and following collection are child nodes of user collection.Using below code snippets I can retrieve users posts directly. But I want to retrieve only followed users posts. If particular user followed another user. That followed users id saved under followings collection **

Container(
        height: 225.0,
        child: StreamBuilder<QuerySnapshot>(
          stream: FirebaseFirestore.instance
              .collection("users")
              .doc(userProfileID)
              .collection("posts")
              .orderBy('Post Date', descending: true)
              .snapshots(),
          builder: (context, snapshot) {
            return !snapshot.hasData
                ? ShimmerPlaceHolder().homePosts(true)
                : snapshot.data.docs.length.toString() == "0"
                    ? Container(
                        height: 100.0,
                        width: 200.0,
                        child: Column(
                          children: [
                            SizedBox(
                              height: 30.0,
                            ),
                            Text(
                              "You have no posts yet",
                              style: TextStyle(
                                  fontSize: AppTheme.AppLightTheme.fontLarge,
                                  fontFamily: 'AirbnbCereal'),
                            ),
                            Image.asset(
                              'assets/images/home_picture.png',
                              height: 100.0,
                              width: 100.0,
                            ),
                          ],
                        ),
                      )
                    : Container(
                        margin: EdgeInsets.symmetric(vertical: 20.0),
                        height: 200,
                        child: ListView.builder(
                          scrollDirection: Axis.horizontal,
                          itemCount: snapshot.data.docs.length,
                          itemBuilder: (BuildContext context, int index) {
                            Post postModel = Post.fromDocument(
                                snapshot.data.docs[index],
                                snapshot.data.docs.length);
                            return Container(
                              width: MediaQuery.of(context).size.width * 0.35,
                              child: Card(
                                //TODO: Add all images radius
                                color: AppTheme.AppLightTheme.unSelectColor,
                                child: snapshot.data.docs.length == null
                                    ? ShimmerPlaceHolder().homePosts(true)
0 Answers
Related