I have created a chat with flutter and I need to use into my app, where 1group of user will chat with another kind of user group. At the moment my chat is developed in this manner and I create record in firebase so:
CollectionReference addMessage = FirebaseFirestore.instance.collection('Messages');
Future<void> createMessageRecord() {
return addMessage
.add(
{ 'id': firebaseUser.uid,
'text': textMessage,
'timeStamp': DateTime.now().millisecondsSinceEpoch.toString(),
},
)
I retrieve them:
StreamBuilder(
stream: FirebaseFirestore.instance.collection('Messages').orderBy('timeStamp', descending: true).snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData)
return Center(child: CircularProgressIndicator());
I display them:
ListView.builder(
reverse: true,
padding: EdgeInsets.only(top: 15.0),
itemCount: snapshot.data.docs.length,
itemBuilder: (BuildContext context, int index) {
final message = snapshot.data.docs[index];
final bool isMe = message['id'] == firebaseUser.uid;
return _buildMessage(message, isMe);
the chat works pretty good but all users of course will have the same chat.
What I want to do is limit the chat displaying just for the 2 users.
the first one who starts the chat and and second one who get.
At the moment I have created into firestore a collection called "Messages" and into I have the 3 documents id
text
timeStamp```
I dont know how to limit the displaying data just for this 2 users