0

I am making a friend req type Functionality So if I tap on add friend button the name of Current Logged in person should be added to the request list of person named I searched.

Firestore Structure

So from my app when I click on add friend button, let say current logged in user is '[email protected]' and I search for '[email protected]' then '[email protected]' user name should be added in the requests array of the person '[email protected]'.

This is my search method to search a user

void onSearch() async {
    await _firestore
        .collection("users")
        .where("email", isEqualTo: _search.text)
        .get()
        .then((value) {
      setState(() {
        userMap = value.docs[0].data();
      });
    });
  }

What should I write in addUser method ?

void addUser() async {
    await _firestore
            .collection("users")
            .where("email", isEqualTo: _search.text)
            .get()
           ;
  }
3
  • It sounds like you're trying to write the new friend request to the database., but none of the code you shared writes to the database, so it's hard to say where the problem is in that code. Commented Jan 1, 2023 at 6:33
  • @FrankvanPuffelen my addUser() code is not complete I don't know how can I add items to array in firestore. Commented Jan 1, 2023 at 6:35
  • Adding items to and removing items from an array is documented here: firebase.google.com/docs/firestore/manage-data/…. To learn how to update all documents that match a query, see stackoverflow.com/questions/63007692/… Commented Jan 1, 2023 at 6:40

1 Answer 1

1

To learn how to add items to and remove items from an array, see the Firebase documentation on updating an array. To learn how to update all documents that match a query, see How to get the document ref to a where clause firestore?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.