Flutter Firestore data not updating sometimes

Viewed 35

Hi i am building an Social media app in which i have a property - "likePercent" - it is basically rating given to a particular post . when i am rating it data is updating in one document but not in another document but some times it updates data on both documents. I am updating this data on 2 places one in the post document userMeme--postId--likePercent = int likePercent . and another in the users--uid--likepercent["likePercent"] . here are some pics and code

 Future<void> likePercent(String postId, String nonCurrentUid,
      String collectionName,int value) async {

    String res = "Some error occurred";
    
    try {
      await FirebaseFirestore.instance.collection('userMeme').doc(postId).update({
        'likePercent' : value
      });      //updating data in post document 

      print("this is $value, uid  $nonCurrentUid , $postId");

      await FirebaseFirestore.instance.collection('users').doc(nonCurrentUid).update({
        'likePercent' : FieldValue.arrayUnion([value])
      });      //updating data in user document inside list 


      res = 'success';
    } catch (err) {
      res = err.toString();
      print(err);
    }
    print(res);
  }

here is the rating bar code -

 RatingBar(
              initialRating: rating,
              direction: Axis.horizontal,
              allowHalfRating: false,
              itemSize: 20,
              itemCount: 5,
              ratingWidget: RatingWidget(
                full : Icon(Icons.star),
                half : Icon(Icons.star_half),
                empty: Icon(Icons.star_border_outlined),

              ),
              itemPadding: EdgeInsets.symmetric(horizontal: 4.0),
              onRatingUpdate: (value) async {
                int rat = value.toInt() * 20;
                        FireStoreMethods().likePercent(post.postId, post.uid, collectionName, rat);

                setState(() {
                });
              },
            ),

console --

I/flutter (27304): this is 60, uid  2ynbUrq4QrNiTCHNLzijgDatc743 , ae9b8500-224c-11ed-8147-bb9400ffa2cc
I/flutter (27304): success

some ss of firestore data --post structureuser strucuture

0 Answers
Related