Comments (16)
https://m.youtube.com/watch?v=B4ZFVBm-Ugs&t=2s
https://m.youtube.com/watch?v=-7EaYUIRBmc&t=6s
from flutter-chat-demo.
Sure!
At the main.dart add this widget inside buildItem.
Widget getLastMessage(String userId, String peerId) {
String groupChatId = '';
if (userId.hashCode <= peerId.hashCode) {
groupChatId = '$userId-$peerId';
} else {
groupChatId = '$peerId-$userId';
}
return StreamBuilder(
stream: _firestore
.collection('messages')
.document(groupChatId)
.collection(groupChatId)
.orderBy('timestamp', descending: true)
.limit(1)
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Text('Loading...');
} else {
var documentsData = snapshot.data.documents;
if (documentsData[0]['type'] == 1) {
return Text('Image message');
} else {
return Text(documentsData[0]['content']);
}
}
}
);
}
from flutter-chat-demo.
But if I don't know apeerId
?
I contacted person A, B and C. I need an overview of last chats, something like this
https://i.stack.imgur.com/OliD7.jpg
from flutter-chat-demo.
So basically you are mapping over the list of users you have chatted. So you have avatar url, user name & id. In this case while mapping items call the Widget getLastMessage with the peerId
of current item id.
Hopefully I was clear! :)
from flutter-chat-demo.
If I understood correctly, then in this case I have to save that list of users I've chatted with (in DB, or cache)?
from flutter-chat-demo.
Yes!
If you are coming from this project example as I said you should call the Widget getLastMessage
at the main.dart
inside buildItem
from flutter-chat-demo.
Whenever a chat is initiated, please check if its the first chat between the current user and the peer, if its the case, save a new instance of that chat with time reference in a firestore table called chats, also save the last message there. when the app loads, take a chat list from that table.in this case, the last message will be stored there. if this is not the first chat, just update the time and the last message sent. this was my approach
from flutter-chat-demo.
Yes!
If you are coming from this project example as I said you should call theWidget getLastMessage
at themain.dart
insidebuildItem
i added the code snippet to my code and this is the error i got
instead of the actual message this is what i got
from flutter-chat-demo.
@akiligedeon I referred your idea and did a similar thing, but one thing I am not getting is that when the user list will be retrieved with the last message, if the last message is a image, how should it be dealt with?
from flutter-chat-demo.
Hi,
Good one. I am using this project example. If current user or peer user get new message, it is coming as push notification in notification tray. Along with push notification, i want to show new message count in chat list screen as badge like whatsapp also.
Attached sample image. How can i acheive this. Please help me on this.
from flutter-chat-demo.
from flutter-chat-demo.
Ok. Thanks for your reply. Any other suggestion without using rx dart package ? As i am not aware of Rxdart.
from flutter-chat-demo.
watch these two videos ,one deal with combine latest the othere deals with stream
from flutter-chat-demo.
Thank you. i will watch.
from flutter-chat-demo.
from flutter-chat-demo.
@Baksman i am trying to achieve something like that whatsapp like the image the guy share above but i have watch the video and i dont no how to go about it
from flutter-chat-demo.
Related Issues (20)
- Firebase function error HOT 1
- firebase storage issues HOT 2
- Overflow issue
- The argument type 'PointerEvent' can't be assigned to the parameter type 'PointerDownEvent'. HOT 2
- Question: (Design related) Recommended way of Firebase[Firestore][Auth] instance state management. HOT 7
- google signin failed HOT 1
- Are the messages being added infinitely in List? HOT 1
- Snapshot _limit variable needs a constraint to prevent from indefinite increment HOT 1
- Inconsitency in group chat id in different platforms HOT 8
- Chat notification
- Add an E2EE functionality: HOT 1
- Add feature to send audio messages
- Upgrade Android SDK HOT 1
- Build failed with exception HOT 1
- Changing firebase credentials HOT 1
- Firebase Error
- What is the version of flutter? HOT 1
- Keyboard hides the message input when in focus HOT 1
- Missing typing indicator
- Reversed Listview auto snaps to bottom when new snapshot stream is fetched
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter-chat-demo.