Can someone tell me the logic to build a real time chat app?

I’m coding a chat app in Flutter and Firebase. What I have done so far is the app will listen for any message using a StreamBuilder. The problem is I can’t figure out how to privately send the messages only to one person. Can someone help me with this?

I’ve used Firebase a bit, but I haven’t used Flutter.

I also assume your using Firestore rather than the real-time-database, as Firestore has more features and is the “newer” of the two. With Firestore, you should be able to create a 1 on 1 real time chat function by creating a "combined key between the 2 user’s who are communicating. With this “combine-key”, you can have a collection of records representing the messages between these users.

Beyond that you should be able to finalize the details, but the main “trick” is to combine the 2 user’s unique id’s in the system so their “communication chain” is identified between them.

This also only supports very few users, so mass group chats aren’t supported with this approach and would need another.

Hope that at least gets the ball rolling!

Good luck, keep building, keep learning!