0

i am currently working on a flutter app which is kinda social media app, right now i am stuck with the idea to implement the add friends feature from a list of contacts who have account in my app, but i can not think of any method of doing so , my app's back-end is handled by Firebase with each user's profile information stored differently in Firestore database,

i want a simple and efficient way to add friends in my app, more like Facebook, Instagram, Snapchat,

can anyone suggest me how to implement this feature in my app?

if so please provide links to pages and documentations!

Thank you

OddlyGhost
  • 128
  • 2
  • 14

1 Answers1

3

There are lots of ways this could be achieved, one is creating a collection Users and each document per user, inside that user document you will have two Lists of user ids 1. friends 2. requests ... so when someone sends a request, add the sender's user-id into requests section inside the receiver's user document, when the user accepts the request delete the user id from the requests and add sender's user-id into friends list.

Root => Users(collection) => userid1(document) => friends(List<String>)
                                               => requests(List<String>)

This is just one way do your research and use what's appropriate for you. :)

Henok
  • 3,293
  • 4
  • 15
  • 36
  • 1
    glad it helped, you can refer [this](https://stackoverflow.com/a/53665475/6798995) on how to add the item to a list inside a document, and if you want to query all the user's sent requests you can use **arrayContains**. these are just a hint I highly recommend to refer the documentations. – Henok Sep 19 '20 at 05:59
  • again thanks a lot mate – OddlyGhost Sep 19 '20 at 06:15