Is it possible to notify a user of a new message in my Flutter chat app without Firestore or FCM?

1,248

I see you have this tagged with C# as well as Flutter. Assuming your backend is C#, you'll want to use a WebSocket solution like SignalR for this.

There is a pub package here that you can use in your Flutter app.

I have a similar setup using SignalR on the backend with the above pub package in-app, and it works very reliably.

Share:
1,248
kalittles
Author by

kalittles

Updated on December 16, 2022

Comments

  • kalittles
    kalittles over 1 year

    I currently have a Flutter application that has a chat feature. I've implemented it by writing standard CRUD operations. When a user sends a message, it posts it to the database. When a user navigates to a chat between two users, it makes an async REST call and grabs all of the messages in the chat. When you type in a message and hit send, it posts a message to the backend and persists it to the SQL DB.

    I currently have no way to "notify" a user of incoming messages. In order to see any new messages from the other user, I actually have to navigate away from the chat window and back to it. At a high level, this makes sense - the client has to request information from the server, so without any sort of event happening on the device, it wouldn't know to listen for a new message.

    I think that the only way to accomplish this is to use some form of push notifications, but is there a way to accomplish this without Firestore? Would I need to create a publish and subscribe service for my backend application? Is this only possible to do by utilizing push notifications in some way?

    And if it isn't, how would I go about learning how to do it?

    I apologize for how broad the question is, but I don't know how "real-time" chat works, and I'd like to get a deeper understanding on how I could implement it without using a pre-built tool.

  • kalittles
    kalittles about 4 years
    Thank you so much - I think the real saving grace here was that this taught me the difference between an HTTP request (half duplex, request response, not natively supported service pushing because it requires client polling or streaming download techniques) compared to WebSocket (full duplex, bi-directional, has service pushing). I didn't understand the difference at all at first. But yes, I have C# as my backend, so this will work really well - thank you so much!
  • Jon Halliday
    Jon Halliday about 4 years
    @kalittles Of course - SignalR is pretty powerful and perfect for chat apps. It might be hard to dig up an end-to-end example for Flutter, but there are a number of chat examples on GitHub where you can at least see how the server is done. The Flutter client is similar to what you'll see in the examples though. Here's one that might help you get started: github.com/aspnet/SignalR-samples/tree/master/ChatSample