Git Product home page Git Product logo

Comments (16)

Baksman avatar Baksman commented on May 16, 2024 1

https://m.youtube.com/watch?v=B4ZFVBm-Ugs&t=2s
https://m.youtube.com/watch?v=-7EaYUIRBmc&t=6s

from flutter-chat-demo.

Nikualla1 avatar Nikualla1 commented on May 16, 2024

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.

harunB10 avatar harunB10 commented on May 16, 2024

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.

Nikualla1 avatar Nikualla1 commented on May 16, 2024

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.

harunB10 avatar harunB10 commented on May 16, 2024

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.

Nikualla1 avatar Nikualla1 commented on May 16, 2024

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.

akiligedeon avatar akiligedeon commented on May 16, 2024

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.

harshraj32 avatar harshraj32 commented on May 16, 2024

Yes!
If you are coming from this project example as I said you should call the Widget getLastMessage at the main.dart inside buildItem

i added the code snippet to my code and this is the error i got
rere

instead of the actual message this is what i got

from flutter-chat-demo.

ramneekkashyap9 avatar ramneekkashyap9 commented on May 16, 2024

@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.

MaheshPeri19 avatar MaheshPeri19 commented on May 16, 2024

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.

whatsapp_badgecount

from flutter-chat-demo.

Baksman avatar Baksman commented on May 16, 2024

from flutter-chat-demo.

MaheshPeri19 avatar MaheshPeri19 commented on May 16, 2024

Ok. Thanks for your reply. Any other suggestion without using rx dart package ? As i am not aware of Rxdart.

from flutter-chat-demo.

Baksman avatar Baksman commented on May 16, 2024

watch these two videos ,one deal with combine latest the othere deals with stream

from flutter-chat-demo.

MaheshPeri19 avatar MaheshPeri19 commented on May 16, 2024

Thank you. i will watch.

from flutter-chat-demo.

mohamedlouati avatar mohamedlouati commented on May 16, 2024

from flutter-chat-demo.

gbbest15 avatar gbbest15 commented on May 16, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.