flutter firestore ‘like’ button is behaving strangely

I used Firebase queries so that when someone clicks the like button, it goes to the ‘sendHearts’ field, and conversely, when someone receives a like, it goes to the ‘receivedHearts’ field. However, as soon as I click the like button, it goes to the wrong place. here is my code.

//receivedLike

Widget _receivedHearts(BuildContext context) {
    final db = FirebaseFirestore.instance;
    final uid = FirebaseAuth.instance.currentUser?.uid;
    return StreamBuilder(
        stream: db
            .collection(AppKeys.users)
            .where('receivedHearts', arrayContains: uid)
            .snapshots(),
        builder: (context, snapshot) {
          // print(snapshot);
          print(uid);
          print('snapshot : ${snapshot.data}');
          List<UsersModel> user = [];
          for (var docSnapshot in snapshot.data?.docs ?? []) {
            print('snapshot : ${snapshot.data?.docs}');
            user.add(UsersModel.fromDocument(docSnapshot));
          }
          if (snapshot.hasError) {
            return Text('Error: ${snapshot.error}');
          }
          switch (snapshot.connectionState) {
            case ConnectionState.waiting:
              return CircularProgressIndicator();
            default:
              return Container(

// sendLike

 Widget _sendHeart(BuildContext context) {
    final db = FirebaseFirestore.instance;
    final uid = FirebaseAuth.instance.currentUser?.uid;
    return StreamBuilder(
        stream: db
            .collection(AppKeys.users)
            .where('sentHearts', arrayContains: uid)
            .snapshots(),
        builder: (context, snapshot) {
          List<UsersModel> user = [];
          for (var docSnapshot in snapshot.data?.docs ?? []) {
            user.add(UsersModel.fromDocument(docSnapshot));
          }
          if (snapshot.hasError) {
            return Text('Error: ${snapshot.error}');
          }
          switch (snapshot.connectionState) {
            case ConnectionState.waiting:
              return CircularProgressIndicator();
            default:
              return Container(

It seems like there’s no problem, even though I’ve checked it multiple times. And I’ve also checked the database, but it seems like everything is going in correctly.

  Future<void> likePost(
      BuildContext context, UsersModel item, bool isLike) async {
    final uid = FirebaseAuth.instance.currentUser?.uid;
    try {
      await FirebaseFirestore.instance
          .collection(AppKeys.users)
          .doc(item.id)
          .update(
        {
          'receivedHearts': FieldValue.arrayUnion([uid])
          // print(doc['sentHearts']);
        },
      );
      await FirebaseFirestore.instance
          .collection(AppKeys.users)
          .doc(uid)
          .update(
        {
          'sentHearts': FieldValue.arrayUnion([item.id]),
        },
      );

      print('sent 값 : ${item.sentHearts}');
      print('receive 값 : ${item.receivedHearts}');
    } catch (e) {
      print(e);
    }
  }

  Future<void> dislikePost(
      BuildContext context, UsersModel item, bool isLike) async {
    final uid = FirebaseAuth.instance.currentUser?.uid;
    try {
      await FirebaseFirestore.instance
          .collection(AppKeys.users)
          .doc(item.id)
          .update(
        {
          'receivedHearts': FieldValue.arrayRemove([uid])
        },
      );
      await FirebaseFirestore.instance
          .collection(AppKeys.users)
          .doc(uid)
          .update(
        {
          'sentHearts': FieldValue.arrayRemove([item.id]),
        },
      );
      // print('receive 값 : ${item.receivedHearts}');
    } catch (e) {
      print(e);
    }
  }

And this is the button logic.

GestureDetector(
                                                onTap: () async {
                                                  // bool isLike = item.sentHearts?.contains(uid) ?? false;

                                                  bool newLikeState = !isLike;
                                                  if (newLikeState) {
                                                    print(
                                                        'newlike : $newLikeState');
                                                    try {
                                                      await likePost(context,
                                                          item, isLike);
                                                      print(' : $isLike');
                                                      setState(() {
                                                        isLike = newLikeState;
                                                      });
                                                    } catch (e) {
                                                      print('faild: $e');
                                                    }
                                                  } else {
                                                    try {
                                                      await dislikePost(context,
                                                          item, isLike);
                                                      print(
                                                          'dislike : $isLike');
                                                      setState(() {
                                                        isLike = !newLikeState;
                                                      });
                                                    } catch (e) {
                                                      print('failed: $e');
                                                    }
                                                  }
                                                  print('final like : $isLike');
                                                },
                                                child: isLike
                                                    ? SvgPicture.asset(
                                                        'assets/icons/smallHeart_on.svg')
                                                    : SvgPicture.asset(
                                                        'assets/icons/smallHeart.svg'),
                                              )

The button is behaving strangely. The “like” is definitely being stored accurately in the database. I really don’t know what’s wrong. I urgently need help!

enter image description here

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật