Message:

Subscribe rss
Blog categories
All | Backendless features
How to Create a Chat App with Backendless SDK for Flutter
May 14, 2019 by Maksym Khobotin

Create Chat App with Flutter SDK

In this article we are going to demonstrate how to create a simple chat application with the new Backendless SDK for Flutter. This will give you an overview of the process needed to integrate your Backendless server-side with your Flutter app client-side. The Backendless SDK for Flutter is currently available for Android and coming soon for iOS.

Setup

First at all, we will create a new Backendless application in console and call it MessagingApp .

Create Messaging App with Flutter SDK

Now we need to create and setup the Flutter project. If you need help installing and running Flutter, please visit official Flutter docs. Let’s create a sample Flutter project and call it messaging_app :

Create Flutter App

Name Flutter App

To use the plugin in Flutter project, we need to add backendless_sdk  as a dependency in pubspec.yaml file:

After that add the following import to Dart code:

Add Backendless SDK to Flutter App

Do not forget to initialize the Backendless SDK. Call Backendless.initApp()  and pass three arguments: application ID, Android API key and iOS API key. These values must be obtained in Backendless Console.

Add Keys to Flutter App

And now we are ready to use the Backendless APIs.

Subscription API

For messaging app we need to subscribe to the channel:

and implement onMessageReceived  function:

Now, when we receive the message from a server we will display the date, author name and the message itself. Note: the  onMessageReceived  function can receive PublishMessageInfo  or String  (just a message) arguments.

Also, we need to add the io.socket  dependency to support real-time messaging for Android clients. Open your build.gradle  file that is located under android/app/  and add the following lines of code:

Add Dependencies to Flutter App

We are done with Subscription API. Now let’s implement message publishing.

Publishing API

First, let’s create some UI and add a TextField  to display messages and an input field:

And implement publishing function:

And that is all. Run the application and say hello!

You can find the full sample project here. Thanks for reading and enjoy using the Backendless platform!

Share this post
Tweet about this on TwitterShare on FacebookGoogle+