0

What im trying to do is filling a card with the necessary data it needs which is userImage and UserFirstname from my users collection and also data from my subcollection(carReviews)in my carInfo collection where i store the necessary review data: subcollection(carReviews)

users collection

StreamBuilder<QuerySnapshot>(
                              stream: FirebaseFirestore.instance
                                  .collection('carInfo')
                                  .doc(snapshot.data!.docs[index]
                                      .get('CaradvId'))
                                  .collection('carReviews')
                                  .snapshots(),
                              builder: (context, snapshot5) {
                                return StreamBuilder<QuerySnapshot>(
                                    stream: FirebaseFirestore.instance
                                        .collection('users')
                                        .where('uid',
                                            isEqualTo: snapshot5
                                                .data!.docs[index]
                                                .get('reviewerId'))
                                        .snapshots(), 
                                    builder: (context, snapshot6) {
                                      return Container(
                                        padding: EdgeInsets.symmetric(
                                            horizontal: 5),
                                        height: MediaQuery.of(context)
                                                .size
                                                .height *
                                            0.225,
                                            child: ListView.builder(
                                                shrinkWrap: true,
                                                scrollDirection:
                                                    Axis.horizontal,
                                                itemCount: snapshot5
                                                    .data!.docs.length,
                                                itemBuilder:
                                                    (BuildContext context,
                                                        int index) {
                                                         
                                                  DateTime date = snapshot5
                                                      .data!.docs[index]
                                                      .get('reviewDate')
                                                      .toDate();
                                                  String dateString =
                                                      DateFormat(
                                                              'dd MMM yyyy')
                                                          .format(date);

                                                  return ConstrainedBox(

When i print snapshot5.data!.docs[index].get('reviewerId') i get the two ids who has reviewed which what is expected however the snapshot6.data!.docs.length is 1 which doesn't make any sense! I have tried using both snapshot6.data!.docs.length & snapshot5.data!.docs.length for the itemcount if i use snapshot6.data!.docs.length i get just one item in list with no errors and if i use snapshot5.data!.docs.length i get range error because it goes through all reviews which are just 2. Me using "hasdata" if statment wont change the output i have tried.

how it looks when i use snapshot5.data!.docs.length

how it looks when i use snapshot6.data!.docs.length

Card(
                                                        elevation: 2,
                                                        child: Container(
                                                          child: Column(
                                                            mainAxisAlignment:
                                                                MainAxisAlignment
                                                                    .start,
                                                            children: [
                                                              Row(
                                                                mainAxisAlignment:
                                                                    MainAxisAlignment
                                                                        .start,
                                                                children: [
                                                                  Container(
                                                                    padding: EdgeInsets.only(
                                                                        left:
                                                                            12.5,
                                                                        top:
                                                                            12.5),
                                                                    height:
                                                                        55,
                                                                    width:
                                                                        55,
                                                                    child:
                                                                        CircleAvatar(
                                                                      backgroundImage:
                                                                          NetworkImage(
                                                                        snapshot6.data!.docs[index].get('userImage'),
                                                                      ), //userimage
                                                                      radius:
                                                                          40,
                                                                    ),
                                                                  ),
                                                                  Container(
                                                                      padding: EdgeInsets.only(
                                                                          top:
                                                                              15),
                                                                      child:
                                                                          Column(
                                                                       crossAxisAlignment:
                                                        CrossAxisAlignment
                                                            .start,
                                                                        children: [
                                                                          Container(  padding: EdgeInsets.only(
                                                                          left:
                                                                              5),child:
                                                                            RatingBar.builder(
                                                                              initialRating: double.parse(snapshot5.data!.docs[index].get('reviewRating')),
                                                                              minRating: 1,
                                                                              direction: Axis.horizontal,
                                                                              allowHalfRating: true,
                                                                              updateOnDrag: false,
                                                                              itemCount: 5,
                                                                              itemSize: 14,
                                                                              itemPadding: EdgeInsets.symmetric(vertical: 0),
                                                                              itemBuilder: (context, _) => Icon(
                                                                                Icons.star,
                                                                                color: Colors.amber,
                                                                              ),
                                                                              onRatingUpdate: (rating) {
                                                                                print(rating);
                                                                              },
                                                                            ),
                                                                          ),
                                                                          SizedBox(height: 7.5),
                                                                          Row(
                                                                            children: [
                                                                              Container(
                                                                                padding: EdgeInsets.only(
                                                                                  left: 7.5,
                                                                                ),
                                                                                child: Text(
                                                                                  snapshot6.data!.docs[index].get('userFirstname'),
                                                                                  overflow: TextOverflow.ellipsis,
                                                                                  maxLines: 1,
                                                                                  style: TextStyle(
                                                                                    fontSize: 10,
                                                                                    fontWeight: FontWeight.w800,
                                                                                    color: Colors.black87,
                                                                                  ),
                                                                                ),
                                                                              ),
                                                                              Container(
                                                                                  padding: EdgeInsets.only(left: 2.5),
                                                                                  child: Text(
                                                                                    dateString,
                                                                                    overflow: TextOverflow.ellipsis,
                                                                                    maxLines: 1,
                                                                                    style: TextStyle(
                                                                                      fontSize: 10,
                                                                                      fontWeight: FontWeight.w800,
                                                                                      color: Colors.black54,
                                                                                    ),
                                                                                  ))
                                                                            ],
                                                                          )
                                                                        ],
                                                                      )),
                                                                ],
                                                              ),
                                                              Container( padding: EdgeInsets.only(
                                                                        left:
                                                                            12.5,
                                                                        top:
                                                                            12.5),
                                                                height: 130,width: MediaQuery.of(
                                                                    context)
                                                                .size
                                                                .width *
                                                            0.75,
                                                                child: Text(snapshot5
                                                                    .data!
                                                                    .docs[
                                                                        index]
                                                                    .get(
                                                                        'reviewContent')),
                                                              )
                                                            ],
                                                          ),
                                                        )),
Arminmos
  • 3
  • 1

0 Answers0