Flutter firestore remove ignore doc

Viewed 17

What I need to do is I have a list of ids and I need to fetch data from firestore and ignore those id which are available on that data (Those data doc id is same which are in ids)

I am doing like this

  getProfiles(BuildContext context) async {
    var profileProvider = Provider.of<profilesProvider>(context, listen: false);
    final userProviderState = Provider.of<userProvider>(context, listen: false);
    final globalProviderState =
        Provider.of<globalProvider>(context, listen: false);

    showDialog(
        context: context,
        barrierDismissible: false,
        builder: (BuildContext context) {
          return spinkit;
        });

    CollectionReference _collectionRef =
        FirebaseFirestore.instance.collection(USER_COLLECTION);
    QuerySnapshot querySnapshot = await _collectionRef.get();
    List allData = querySnapshot.docs.map((doc) => doc.data()).toList();
    final likestate = Provider.of<LikeDislikeProvider>(context, listen: false);

    for (var i = 0; i < likestate.likedislikePRofiles.length; i++) {
      allData.removeWhere(
          (item) => item['id'] == likestate.likedislikePRofiles[i].oppositeId);
    }
    
    allData.forEach((element) {
      GeoPoint point = element['Location'];
      if (calculateDistance(
          userProviderState.user[0].Latitude,
          userProviderState.user[0].Longitude,
          point.latitude,
          point.longitude)) {
        profileProvider.addProfile(element);
      } else {}
    });
    Navigator.pop(context);
  }

But in this issue is I am getting all data then by for loop i am removing it which I don't think is good when data is too much. So what I want is from query I can ignore those data which doc id is same as in arrays.

Here is screenshot docid and id in data is same. I have list of doc id which needs to ignore.

enter image description here

0 Answers
Related