For AI agents: Find a documentation index at https://talkjs.com/llms.txt (full content at https://talkjs.com/llms-full.txt). Get a markdown version of any page by appending .md to its URL path.
Skip to content

Flutter

Flutter chat SDK with push notifications for Android and iOS

Add a ready-made chat screen to your Android and iOS apps with one Flutter package. We store and deliver every message, so you don’t write a chat backend. We handle push notifications too: upload your Firebase and Apple keys once, and we do the sending. You can be live in days.

import 'package:flutter/material.dart';
import 'package:talkjs_flutter/talkjs_flutter.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final session = Session(appId: '<APP_ID>');

    final me = session.getUser(
      id: '123456',
      name: 'Alice',
      email: ['alice@example.com'],
      photoUrl: 'https://talkjs.com/images/avatar-1.jpg',
      welcomeMessage: 'Hey there! How are you? :-)',
    );

    session.me = me;

    final other = session.getUser(
      id: '654321',
      name: 'Sebastian',
      email: ['Sebastian@example.com'],
      photoUrl: 'https://talkjs.com/images/avatar-5.jpg',
      welcomeMessage: 'Hey, how can I help?',
    );

    final conversation = session.getConversation(
      id: Talk.oneOnOneId(me.id, other.id),
      participants: {Participant(me), Participant(other)},
    );

    return MaterialApp(
      title: 'TalkJS Demo',
      home: Scaffold(
        appBar: AppBar(
          title: const Text('TalkJS Demo'),
        ),
        body: ChatBox(
          session: session,
          conversation: conversation,
        ),
      ),
    );
  }
}
You
Hey, I’m having trouble accessing my account. It says my password is incorrect.
5m ago
SupportBot
Hi there! No problem — let’s get that sorted. Have you tried resetting your password using the 'Forgot password?' link?
4m ago
thinking
thumbs-up
You
Yes, but I haven’t received the reset email yet.
3m ago
SupportBot
Thanks for confirming. I’ve just sent a new reset link to your email. Please check your inbox and spam folder.
2m ago
SupportBot
Is there anything else I can help you with?
just now
Got it — checking my inbox now!
Flutter Dev
Hey, I'm trying to manage state with Provider, but my widget isn't rebuilding. Any ideas?
8m ago
You
Are you calling notifyListeners() after updating the value in your provider? That’s needed to trigger a rebuild.
6m ago
Flutter Dev
Ah, I think I missed that. Let me check.
5m ago
ok-hand
thinking
You
Yep, that's usually the issue when changes don't propagate.
2m ago
Flutter Dev
typing...
just now
Write a reply...

The chat backend your Flutter app doesn’t need

The SDK’s ChatBox and ConversationList widgets are the pre-built chat UI. Behind them, we run the parts you’d otherwise build and host yourself.

Message storage and history

We store every conversation and message, with unlimited message retention on every plan. Your app doesn’t need its own chat database.

Message delivery

Each message reaches everyone in the conversation and shows up in your ChatBox and ConversationList widgets. There’s no messaging server for you to build or host.

Push notifications through FCM and APNs

New-message notifications go out through Firebase Cloud Messaging on Android and Apple Push Notification service on iOS. There’s no push server on your side, and mobile push is on every plan.

Classtime
Decathlon
Riot Games
Hyundai

From flutter pub add to your first push notification

Four steps. You’ll have a working chat on a device after step 2, before you set up authentication or write a line of server code.

01

Install talkjs_flutter from pub.dev

Add the talkjs_flutter package to your app. It needs Flutter 3.38 or later and Dart 3.10 or later, and it runs on Android API 24 or later and iOS 15 or later. On Android, also turn on core library desugaring with Java 17 and desugar_jdk_libs:2.1.5, as the getting-started guide shows.

flutter pub add talkjs_flutter

02

Put a ChatBox in your widget tree

Create a Session with your app ID and set session.me to the current user right away. Then create the other user, get a one-on-one conversation with Talk.oneOnOneId, and pass the session and conversation to a ChatBox.

This is the sample from the Flutter getting-started guide. It passes no token, which works while authentication is off, and that’s how every new TalkJS account starts. Step 3 adds the token. The sample sets no role on its users. Add a role to each user, or getUser logs a warning.

import 'package:flutter/material.dart';
import 'package:talkjs_flutter/talkjs_flutter.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    final session = Session(appId: '<APP_ID>');

    final me = session.getUser(
      id: '123456',
      name: 'Alice',
      email: ['alice@example.com'],
      photoUrl: 'https://talkjs.com/images/avatar-1.jpg',
      welcomeMessage: 'Hey there! How are you? :-)',
    );

    session.me = me;

    final other = session.getUser(
      id: '654321',
      name: 'Sebastian',
      email: ['Sebastian@example.com'],
      photoUrl: 'https://talkjs.com/images/avatar-5.jpg',
      welcomeMessage: 'Hey, how can I help?',
    );

    final conversation = session.getConversation(
      id: Talk.oneOnOneId(me.id, other.id),
      participants: {Participant(me), Participant(other)},
    );

    return MaterialApp(
      title: 'TalkJS Demo',
      home: Scaffold(
        appBar: AppBar(
          title: const Text('TalkJS Demo'),
        ),
        body: ChatBox(
          session: session,
          conversation: conversation,
        ),
      ),
    );
  }
}

03

Sign a user token on your server

Without authentication, anyone could send or read messages as any user. So before you go live, your backend signs a JWT for each user with your secret key, and your app passes it to the Session as token. For tokens that refresh, pass a tokenFetcher that gets a new token from your server.

Here’s the Dart version from the authentication docs, using dart_jsonwebtoken. It runs on your server, and the token expires after one day. Backend not in Dart? The same page has it in Node.js, Python, PHP, Ruby, Java, C#, Go and Elixir.

// Uses `dart_jsonwebtoken`: https://pub.dev/packages/dart_jsonwebtoken
import 'package:dart_jsonwebtoken/dart_jsonwebtoken.dart';

void main(List<String> arguments) {
  final jwt = JWT(
    {'tokenType': 'user'},
    issuer: '<APP_ID>',
    subject: '<USER_ID>',
  );

  final encoded_jwt = jwt.sign(
    SecretKey('<SECRET_KEY>'),
    expiresIn: Duration(days: 1),
  );

  print(encoded_jwt);
}

Never put the secret key in your Flutter app. When the token flow works, turn on authentication on the Settings page of your dashboard, under Security settings.

04

Turn on push with FCM and APNs

We send chat notifications through Firebase Cloud Messaging (FCM) on Android and Apple Push Notification service (APNs) on iOS. Your part is a few platform settings, your keys in the dashboard and one handler in your app. The Flutter push notifications guide has every step in full.

Android (FCM)

  1. Run flutterfire configure to connect your app to Firebase. You can skip installing firebase_core and firebase_messaging, because talkjs_flutter already depends on them.
  2. Upload your Firebase service account JSON key on the Settings page of your TalkJS dashboard, under Mobile push notifications, and save.
  3. If your app targets Android 13 or higher, declare the POST_NOTIFICATIONS permission in your manifest and request it at runtime with flutter_local_notifications.

iOS (APNs)

  1. In Xcode, add the Push Notifications capability, and select Remote notifications under Background Modes.
  2. On the Settings page of your TalkJS dashboard, add your .p8 signing key, Key ID, Team ID and bundle ID.
  3. Set the notification center delegate in your AppDelegate. The guide shows it in Swift and Objective-C.

In your Flutter code

Call Talk.registerPushNotificationHandlers in main(), before runApp(). It also creates the Android notification channel. Without that channel, notifications don’t appear.

await Talk.registerPushNotificationHandlers(
  androidSettings: const AndroidSettings(
    channelId: 'com.example.talkjsflutter.messages',
    channelName: 'Messages',
  ),
  iosSettings: const IOSSettings(useFirebase: false),
);

runApp(const MyApp());

Last, pass enablePushNotifications: true when you create the Session. Now your users get notifications for new messages while the app is in the background.

Want iOS notifications to go through Firebase too? We support that as well, and the push guide covers the setup. We can also reach users by email and SMS. See notifications.

From here, add a ConversationList so users can see all their conversations and open one in a ChatBox.

Read the Flutter SDK docs
Styleseat logo
Because implementing TalkJS was as fast and easy as it was, we were able to greenlight and move this project along very quickly. Had we not chosen this path, the feature would have either been delayed, or shelved due to the resources needed to implement it.
Sean Elliot
Engineering Manager, Styleseat

Style the Flutter chat with HTML and CSS

Your chat should look like your app, not like a chat vendor’s. You edit the Flutter chat’s HTML and CSS in the TalkJS Theme Editor, the same theming system our Classic JavaScript SDK uses. To turn it on, open Project settings in your dashboard and select Enable UI Theme Editor (Classic SDKs).

What flutter_chat_ui and Firebase leave to you

flutter_chat_ui is a free, open-source chat UI package under the Apache 2.0 license. It works with any backend, so storing and delivering messages is on you. Its InMemoryChatController keeps messages in memory only, so they’re gone when the app session ends unless you connect storage. Pair it with Firebase, and push alone adds two jobs:

  • A trusted server running the Firebase Admin SDK, since FCM messages sent from code have to come from a server, plus a way to get each device’s token to it.
  • Send code that handles duplicate events, since a Firestore trigger can run your function more than once.

An AI coding agent can write that code for you. You’d still host it, pay for it and fix it when it breaks. With TalkJS, message storage and history, delivery, push sending and moderation tools are already running. See pricing.

FAQs

Yes. The TalkJS Flutter SDK, talkjs_flutter on pub.dev, ships pre-built chat widgets for Android and iOS apps: ChatBox for one conversation and ConversationList for the list of a user’s conversations. TalkJS stores and delivers the messages and sends push notifications through FCM and APNs, so you don’t build a chat backend.

Yes. TalkJS has three, depending on where your code runs. The talkjs_flutter SDK gives you the pre-built ChatBox and ConversationList widgets. The Flutter Data API, talkjs_core_flutter, is a headless messaging SDK: your own UI sends messages and subscribes to them in real time. It supports Android only, so on iOS use talkjs_flutter. On your server, the REST API manages users, conversations, and messages.

Flutter 3.38 or later, with Dart 3.10 or later. On pub.dev, the current talkjs_flutter release lists Android API 24 or later and iOS 15 or later. On Android, you also turn on core library desugaring with Java 17, as the getting-started guide shows.

TalkJS sends them for you, through Firebase Cloud Messaging (FCM) on Android and Apple Push Notification service (APNs) on iOS, so you don’t run a push server. You upload your Firebase service account key and your APNs .p8 key in the TalkJS dashboard, call Talk.registerPushNotificationHandlers before runApp(), and pass enablePushNotifications: true to the Session.

Yes. You edit the chat’s HTML and CSS in the TalkJS Theme Editor, the same theming system the Classic JavaScript SDK uses. To turn it on, open Project settings in your dashboard and, under Dashboard settings, select Enable UI Theme Editor (Classic SDKs).

All four ship a Flutter SDK with a pre-built chat UI and support push notifications through FCM and APNs. TalkJS keeps message history with no time limit on every plan, while Sendbird and CometChat keep 6 months by default. TalkJS also sends email and SMS notifications on every plan (SMS costs extra), and replies to an email notification go back into the chat. On Sendbird, you build those with webhooks, and on CometChat they need the Advanced plan and your own SendGrid or Twilio account. Where the others lead: Sendbird, Stream, and CometChat sell voice and video calling, and offer HIPAA compliance on some plans. TalkJS doesn’t, so you’d add a calling provider of your choice. See TalkJS vs Sendbird, TalkJS vs Stream, and TalkJS vs CometChat.

Yes. Every TalkJS plan includes a free development mode with no time limit, so you can build and test your Flutter chat before you pay. You pick a paid plan when you go live with real users. Plans are priced per monthly active user, with unlimited conversations and messages. See pricing for details.