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,
),
),
);
}
}


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.
We store every conversation and message, with unlimited message retention on every plan. Your app doesn’t need its own chat database.
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.
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.
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_flutter02
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)
- Run
flutterfire configureto connect your app to Firebase. You can skip installingfirebase_coreandfirebase_messaging, becausetalkjs_flutteralready depends on them. - Upload your Firebase service account JSON key on the Settings page of your TalkJS dashboard, under Mobile push notifications, and save.
- If your app targets Android 13 or higher, declare the
POST_NOTIFICATIONSpermission in your manifest and request it at runtime withflutter_local_notifications.
iOS (APNs)
- In Xcode, add the Push Notifications capability, and select Remote notifications under Background Modes.
- On the Settings page of your TalkJS dashboard, add your
.p8signing key, Key ID, Team ID and bundle ID. - 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.
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.
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.
