Add calls, chat and a prebuilt call UI to your Flutter app. Wire the whole call flow in two lines with SocritsCallUI, or drop down to the client callbacks for full control.
Install
1flutter pub add socrits livekit_client permission_handlerAdd platform permissions (Android needs min SDK 21):
1<!-- android/app/src/main/AndroidManifest.xml -->2<uses-permission android:name="android.permission.INTERNET"/>3<uses-permission android:name="android.permission.CAMERA"/>4<uses-permission android:name="android.permission.RECORD_AUDIO"/>5<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>6<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>78<!-- ios/Runner/Info.plist -->9<key>NSCameraUsageDescription</key><string>Video calls</string>10<key>NSMicrophoneUsageDescription</key><string>Voice calls</string>Initialize & connect
Create the client with your Socrits base URL and connect the signalling socket. The app authenticates with a session token your backend mints — see Server & tokens.
1import 'package:socrits/socrits.dart';2import 'package:livekit_client/livekit_client.dart' as lk;34final client = Socrits(baseUrl: 'https://api.socrits.com');56// Connect the signalling socket. Your backend issues the user's session token7// (POST /v1/session with your sk_live_ key) — never embed the key in the app.8await client.connect(9 sessionEndpoint: 'https://your-backend.com/socrits/session', // returns { token }10 userId: 'alice',11 userName: 'Alice',12);13// (or, if you already have a token) await client.connect(userToken: token, userId: 'alice');Option A — zero-glue calling (recommended)
SocritsCallUI wires the entire call flow for you — the ZEGO ZegoUIKitPrebuiltCallInvitationService equivalent. Attach it once after connect() and incoming calls ring with a prebuilt screen, navigate to the call UI on accept, and tear down on hang-up / decline / timeout — no orchestration code.
1import 'package:socrits/socrits.dart';23// 1) Give MaterialApp a navigator key so the SDK can show the ring + call UI.4final navKey = GlobalKey<NavigatorState>();5// MaterialApp(navigatorKey: navKey, home: ...)67// 2) After connect(), wire the whole call flow — ONCE.8SocritsCallUI.instance.attach(9 client: client,10 navigatorKey: navKey,11 selfName: 'Alice',12);13// That's it. Incoming calls now ring with a prebuilt screen, navigate to the14// call UI on accept, and tear down on hang-up / decline / timeout — automatically.Start a call with one method or a drop-in button:
1// Start a call from anywhere:2SocritsCallUI.instance.call(userId: 'bob', displayName: 'Bob', mode: CallMode.video);34// …or drop a button next to a user (the ZegoSendCallInvitationButton equivalent):5SocritsCallButton(inviteeUserId: 'bob', inviteeName: 'Bob', isVideo: true)SocritsCallUI.instance.attach(client, navigatorKey)— one-time setup; also routes offline (native CallKit) Accept/Decline into the same flow..call(userId:, mode:)/SocritsCallButton— place an outgoing call; the prebuiltSocritsRingScreenhandles the rest.- Pass a
config:to theme the screens, set a ringtone, show profile photos and overlays, or hide controls — see Customize the call UI. - Need custom billing, a reconnection grace window, or your own call screen? Use Option B below (or the Express tier).
SocritsCallUI you can skip the SocritsCallKit.listen(...) step; it’s wired for you.Customize the call UI
The prebuilt screens are fully themeable from code via SocritsCallConfig — the ZEGO ZegoUIKitPrebuiltCallConfig equivalent. Colours, ringtone, profile photos, an overlay on top of the call, custom backgrounds, translated text, video quality, a session time limit — all optional, override only what you need.
1import 'package:socrits/socrits.dart';2import 'package:flutter/material.dart';34// Everything visual goes through SocritsCallConfig (the ZEGO ...CallConfig5// equivalent). Every field is optional — override only what you need.6SocritsCallUI.instance.attach(7 client: client,8 navigatorKey: navKey,9 selfName: 'Alice',10 config: SocritsCallConfig(11 // 1) Theme — brand colours + text styles12 theme: const SocritsCallTheme(13 accent: Color(0xFFCC529F), // pulse rings, avatar ring, call button14 background: Color(0xFF101018), // in-call background15 ringBackground: Color(0xFF0E0E12), // ring screen background16 endCallColor: Color(0xFFE53935),17 acceptCallColor: Color(0xFF2ECC71),18 // voiceGradient, controlColor, onCallText, secondaryText,19 // nameTextStyle, durationTextStyle … all overridable20 ),2122 // 2) Ringtone while ringing (in-app / foreground)23 ringtone: const SocritsRingtone.asset('assets/ring.mp3'), // or .system() / .none()24 // outgoingRingtone: const SocritsRingtone.system(), // caller side (default: none)2526 // 3) Profile photo on the ring + call screens27 selfAvatarUrl: me.photoUrl, // your photo, shown to the callee28 avatarUrlResolver: (userId) => directory[userId], // incoming calls → their photo29 // avatarBuilder: (ctx, size, userId, name) => MyAvatar(userId), // full custom3031 // 4) Overlay drawn on top of the call (coin balance, timer, report button…)32 foregroundBuilder: (ctx, room) => const CoinBalanceBanner(),3334 // 5) Behaviour: hide controls, timer, confirm hang-up, initial media state35 showSpeakerButton: true,36 showFlipButton: true,37 showVideoButton: true,38 showMuteButton: true,39 showDuration: true,40 confirmHangUp: true,41 startWithSpeakerOn: true,42 ),43);4445// Per-call avatar (overrides the resolver for this call):46SocritsCallUI.instance.call(47 userId: 'bob', displayName: 'Bob', avatarUrl: bob.photoUrl, mode: CallMode.video);48// SocritsCallButton(inviteeUserId: 'bob', inviteeName: 'Bob', inviteeAvatarUrl: bob.photoUrl)What you can customize
- Theme (
SocritsCallTheme) —accent,background,ringBackground,endCallColor,acceptCallColor,voiceGradient, control colours, andnameTextStyle/durationTextStyle. - Ringtone (
SocritsRingtone) —.system()(device default),.asset('assets/ring.mp3')(your own sound), or.none(). SeparateoutgoingRingtonefor the caller. - Profile photo —
selfAvatarUrl(your photo, forwarded to the callee),avatarUrlResolver(resolve incoming callers by id), a per-callavatarUrl, or a fullavatarBuilder. Falls back to the name’s initial. - Overlay —
foregroundBuilder(ctx, room)draws any widget over the call (coin balance, timer, report button) — the ZEGOconfig.foregroundequivalent. - Controls & behaviour —
showSpeakerButton/showFlipButton/showVideoButton/showMuteButton,showDuration,confirmHangUp, andstartWithMicOn/startWithCameraOn/startWithSpeakerOn.
More options (0.4.0)
A second group of config, all useful across every kind of call — telehealth, conferencing, tutoring, support, social:
1config: SocritsCallConfig(2 // 6) Translate / reword every on-screen string (i18n)3 text: const SocritsCallText(4 connecting: 'Connexion…',5 incomingVideoCall: 'Appel vidéo entrant',6 accept: 'Répondre', decline: 'Refuser', end: 'Raccrocher',7 // speaker, flip, video, mute, mic, camera, cancel, calling,8 // hangUpConfirm / hangUpStay / hangUpLeave … all overridable9 ),1011 // 7) Custom background behind the call (branded art, blur, gradient).12 // Avatar + name + controls draw on top; a live remote video covers it.13 backgroundBuilder: (ctx, isVideo) => const BrandedWaitingRoom(),1415 // 8) On-video display16 videoFit: SocritsVideoFit.cover, // or .contain (fit, no crop)17 mirrorLocalVideo: true, // mirror your own self-view18 showSelfView: true, // hide your own PiP with false1920 // 9) Camera resolution vs bandwidth21 videoQuality: SocritsVideoQuality.high, // auto | low ~180p | medium ~360p | high ~720p2223 // 10) Session length — auto-end + live timer (trials, metered calls, SLA)24 maxCallDuration: const Duration(minutes: 30),25 onDuration: (elapsed) => billing.tick(elapsed),2627 // 11) Network drops — a "Reconnecting…" overlay shows automatically. Freeze28 // your OWN coin/usage billing while it recovers so nobody pays for downtime.29 onBillingFrozen: (frozen) => billing.setFrozen(frozen), // true on drop, false on recover/end30 reconnectGrace: const Duration(seconds: 60), // give up & end after this31 // onReconnecting / onReconnected / showReconnectingOverlay also available32)- Translate every string (
SocritsCallText) — one object holds all user-visible text on the ring + call screens (status lines, button captions, hang-up dialog). Override only what you need, or supply a fully localised set. - Custom background —
backgroundBuilder(ctx, isVideo)draws branded art, a blurred image or a gradient behind the call; avatar, name and controls sit on top, and a live remote video covers it. Works on the ring screen and the voice/connecting stage too. - On-video display —
videoFit(covercrop-to-fill vscontainfit-with-letterbox so nothing is cropped),mirrorLocalVideo(mirror the self-view),showSelfView(hide your own picture-in-picture). - Video quality —
videoQuality:auto/low(≈180p) /medium(≈360p) /high(≈720p) trades camera resolution for bandwidth on weak networks. - Session length —
maxCallDurationauto-ends the call when reached (trials, metered sessions, meeting/lesson caps) andonDurationfires every second with the live elapsed time (billing meter, countdown, SLA timer).
Network drops & reconnection (0.6.0)
When the network drops mid-call the prebuilt screen shows a themed “Reconnecting…” overlay while LiveKit auto-recovers, then clears it on reconnect — no silent freeze, no instant dismissal. The key hook for metered apps is onBillingFrozen:
onBillingFrozen(bool)— firestruethe instant a drop begins andfalsewhen it recovers (or the call ends). Freeze/resume your own coin/usage billing on it so a user is never charged for downtime. (The same contract as the ExpressSocritsCallGuard, now inside the UIKit.)reconnectGrace(default 60s) — how long to stay reconnecting before giving up and ending; a larger value defers more to LiveKit’s own recovery. The call still ends immediately if the link is reported permanently lost.onReconnecting/onReconnected— lifecycle hooks;showReconnectingOverlay: falseturns off the built-in overlay if you render your own;SocritsCallText.reconnecting/.reconnectedtranslate the strings.
Replace a screen entirely
Want your own ring or call screen but keep the Socrits flow (ring, accept, offline push, teardown)? Hand SocritsCallConfig a builder:
1// Keep the Socrits flow (ring/accept/offline/teardown) but render your OWN screens.2config: SocritsCallConfig(3 // Replace the whole ring screen:4 ringBuilder: (ctx, r) => MyRingScreen(5 name: r.title, incoming: r.incoming, isVideo: r.video, avatarUrl: r.avatarUrl,6 onAccept: r.onAccept, onDecline: r.onDecline, onCancel: r.onCancel,7 ),8 // …and / or the whole in-call screen (you get the connected lk.Room):9 callBuilder: (ctx, room, onHangUp) => MyCallScreen(room: room, onHangUp: onHangUp),10),SocritsCallKit — see Offline ringing below.Option B — manual control
Prefer to drive navigation and billing yourself? Wire the client callbacks directly. Everything below is what SocritsCallUI does under the hood.
1// Wire these once, right after connect()2client.onIncomingCall = (IncomingCall call) {3 // show your ringing screen, then accept or reject:4 // final room = await client.accept(call);5 // client.reject(call);6};7client.onCallConnected = (lk.Room room, CallMode mode) {8 // both sides are in the room now — show the call screen (see below)9};10client.onCallRejected = (callId) { /* callee declined */ };11client.onCallEnded = (reason) { /* ring ended before connecting: timeout | cancelled */ };12client.onCallHungUp = (callId) { /* peer hung up a LIVE call (explicit call:end) */ };1314// End a live call (tells the peer immediately, vs a silent drop):15// client.endCall(callId);1617// Offline ringing: register the device's FCM token so Socrits can push a ring18client.registerDevice(fcmToken, platform: 'android');Make & receive a call
1// Caller: start a call. Returns a callId; the callee gets onIncomingCall.2final callId = await client.invite(3 toUserId: 'bob',4 mode: CallMode.video, // or CallMode.voice5);67// Callee: inside onIncomingCall8final room = await client.accept(call); // joins the media room9// onCallConnected fires on BOTH sides with the connected lk.Room.Render the prebuilt call screen
SocritsCallView is a complete WhatsApp-style call screen: remote video full-screen, your camera in a PiP, a live timer, and Speaker / Flip / Video / Mute / End controls (voice calls show a pulsing avatar). Hand it the connected room and you’re done.
1import 'package:socrits/socrits.dart';23client.onCallConnected = (room, mode) {4 Navigator.of(context).push(MaterialPageRoute(5 builder: (_) => Scaffold(6 body: SocritsCallView(7 room: room,8 title: 'Bob',9 allowVideo: mode == CallMode.video, // voice call → hides Video/Flip, stays audio-only10 startedAt: client.lastStartedAt, // same duration on both sides11 initialCam: mode == CallMode.video,12 initialMic: true,13 initialSpeaker: mode == CallMode.video, // video → speaker, voice → earpiece14 onHangUp: () => Navigator.of(context).pop(),15 ),16 ),17 ));18};Widget parameters
room— the connectedlk.Roomfromaccept()/onCallConnected. Required.title— name shown for the other party.allowVideo— setfalsefor a voice call to hide the Video/Flip controls and keep it audio-only (can’t switch to video). Defaulttrue. Added in 0.1.8.startedAt— server start time (epoch ms) so both parties show the same duration; passclient.lastStartedAt. Added in 0.1.8.initialMic/initialCam— starting mic/camera state (default true).initialSpeaker— start on loudspeaker (true) or earpiece. Defaulttrue; set it from your ring screen (video → speaker, voice → earpiece). Added in 0.1.7.theme— aSocritsCallThemefor colours + text (see Customize the call UI). Added in 0.3.0.avatarUrl/avatarBuilder— show the other party’s photo on the voice stage (falls back to the initial). Added in 0.3.0.foregroundBuilder— overlay a widget on the call (coin balance, timer…). Added in 0.3.0.showSpeakerButton/showFlipButton/showVideoButton/showMuteButton/showDuration— toggle individual controls;confirmHangUpasks before leaving. Added in 0.3.0.text— aSocritsCallTextto translate / reword every on-screen string. Added in 0.4.0.backgroundBuilder(ctx, isVideo)— a custom background behind the call. Added in 0.4.0.videoFit(cover / contain),mirrorLocalVideo,showSelfView— on-video display options. Added in 0.4.0.videoQuality— camera resolution preset (auto / low / medium / high). Added in 0.4.0.maxDuration— auto-end the call at a hard cap;onDurationfires every second with the elapsed time. Added in 0.4.0.onBillingFrozen(freeze your billing on a drop),onReconnecting/onReconnected,reconnectGrace,showReconnectingOverlay— network-drop handling. Added in 0.6.0.onHangUp— called when the user taps End or the call ends; pop your screen here.
Option C — without the UI-Kit
Prefer your own design? accept() and onCallConnected give you the raw LiveKit Room. Control tracks and render video yourself with livekit_client:
1// You get the raw LiveKit Room from accept() / onCallConnected — build any UI you want.2final lk.Room room = await client.accept(call);34// controls5await room.localParticipant?.setMicrophoneEnabled(true);6await room.localParticipant?.setCameraEnabled(mode == CallMode.video);78// render remote video9final listener = room.createListener();10listener.on<lk.TrackSubscribedEvent>((e) {11 if (e.track is lk.VideoTrack) {12 setState(() => remote = e.track as lk.VideoTrack);13 }14});15// in build(): if (remote != null) lk.VideoTrackRenderer(remote!)1617// end the call18await room.disconnect();Offline ringing
When the callee’s app is backgrounded or killed its socket is paused, so a socketonIncomingCall never arrives. Socrits instead sends a high-priority FCM data push, and SocritsCallKit turns it into the native full-screen incoming-call screen (over the lock screen on Android, CallKit on iOS). Registering the FCM token alone is not enough — wire these four steps:
1// socrits bundles flutter_callkit_incoming; you also need firebase_core +2// firebase_messaging for the push itself.3import 'package:firebase_messaging/firebase_messaging.dart';4import 'package:socrits/socrits.dart';56// 1) Top-level FCM background handler — runs when the app is killed/backgrounded.7@pragma('vm:entry-point')8Future<void> _bg(RemoteMessage m) async {9 await SocritsCallKit.onPushData(m.data); // raises the native full-screen ring10}1112void main() {13 FirebaseMessaging.onBackgroundMessage(_bg);14 // 2) Foreground pushes (harmless if your live socket already rang):15 FirebaseMessaging.onMessage.listen((m) => SocritsCallKit.onPushData(m.data));16 runApp(const MyApp());17}If you use SocritsCallUI (Option A), the native Accept/Decline routing below is already done for you — skip to step 4 (registerDevice). Wiring it manually (Option B):
1// 3) Route the OS Accept / Decline — register ONCE, high in the widget tree.2SocritsCallKit.appName = 'MyApp';3SocritsCallKit.listen(4 onAccept: (callId, extra) async {5 // reconnect first if the app was cold-started by the ring:6 await client.connect(userToken: await mintToken(), userId: me);7 await client.acceptCallById(callId); // joins the room → onCallConnected fires8 },9 onDecline: (callId) => client.rejectCallById(callId),10);1112// 4) After connect(), register this device's FCM token so Socrits can ring it:13client.registerDevice(14 await FirebaseMessaging.instance.getToken(),15 platform: 'android',16);SocritsCallKit.onPushData(data)— turns a Socrits FCM data message into the native ring. Safe to call from the background isolate.SocritsCallKit.listen(onAccept, onDecline)— routes the OS Accept/Decline back to your client;onAcceptreconnects (if cold-started) then callsacceptCallById.client.acceptCallById(callId)/rejectCallById(callId)— answer a push-delivered call that had no prioronIncomingCall.registerDevice(fcmToken)— call afterconnect()so Socrits knows where to push.
Theme the native ring
The full-screen offline ring is styled on SocritsCallKit — separately from the in-app SocritsCallConfig theme. The caller’s photo rides the push automatically when you set config.selfAvatarUrl.
1// The native (offline) ring is themed separately from the in-app screens.2SocritsCallKit.appName = 'MyApp';3SocritsCallKit.ringtonePath = 'ringtone'; // res/raw/ringtone.mp3 (Android) /4 // bundled sound (iOS), or 'system_ringtone_default'5SocritsCallKit.backgroundColorHex = '#CC529F'; // full-screen background (Android)6SocritsCallKit.acceptColorHex = '#2ECC71'; // Accept action colour7// The caller's photo rides the push automatically when you set config.selfAvatarUrl.google-services.json into your app too. Without this, registerDevice() stores a token Socrits can’t reach. Fire a test ring from Development Tools → Push debug.flutter_callkit_incoming (bundled with socrits) needs its full-screen-intent activity + broadcast receiver and the call permissions in your Android manifest — see its README. And on Xiaomi / Oppo / Vivo, enable Autostart and set battery to “No restrictions” for your app, or the OS blocks the wake-up push while the app is killed.Chat
1// 1:1 or group chat rides the same connection2client.onMessage = (ChatMessage m) { /* append to the thread */ };34await client.sendMessage(toUserId: 'bob', text: 'Hey!');5final history = await client.messageHistory(conversationId, limit: 30);6final convos = await client.conversations();7client.setTyping(conversationId, true);8client.markRead(conversationId);