FLUTTER • VIDEO CALLING • STEP-BY-STEP

How to add video calling to a Flutter app

Build a one-to-one video call in Flutter with the RTCExpress video calling SDK plugin from pub.dev. You will have two Android phones on a video call with full-screen remote video, a small self-view, mute, camera on/off, camera flip and hang up, without running any media servers yourself.

Video calling needs the Pro planVideo calls and screen share are part of Pro ($29/month or $290/year, 10,000 video minutes a month). You can buy it from Billing in the customer console by card or UPI. On the Free plan the server answers a video call with plan_feature_denied; try the Flutter voice calling tutorial first, which works on Free. See pricing.

1. What you need

  • Flutter 3.19 or newer (flutter --version).
  • Two Android phones with cameras, Android 7.0 (API 24) or newer. Emulators work for testing, but their virtual cameras show a test pattern.
  • An RTCExpress project on the Pro plan. Its App ID is in the customer console.

The RTCVideoView widget is Android-only today. iOS support in the Flutter plugin is experimental, and on iOS the widget throws UnsupportedError.

2. Create an app and install the plugin

Start from a new Flutter project, then add the rtcexpress plugin and permission_handler, which asks the user for camera and microphone access:

flutter create video_call_demo
cd video_call_demo
flutter pub add rtcexpress permission_handler

3. Set the Android minimum version

Open android/app/build.gradle.kts (or build.gradle in older projects) and make sure the minimum SDK is at least 24:

defaultConfig {
    minSdk = 24
    // ...keep the other generated values
}

You don't need to edit AndroidManifest.xml. The plugin already declares the internet, camera and microphone permissions; your app only asks the user at runtime, which the code below does just before a call starts.

4. Write the video call screen

Replace lib/main.dart with this. It is the whole app: one screen that connects, joins a room, places or answers a video call, and shows both cameras.

import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:rtcexpress/rtcexpress.dart';

// Test values from the console's Token tools, passed with --dart-define.
// In a real app, fetch the token from your own backend. Never ship an App Secret.
const appId = String.fromEnvironment('RTC_APP_ID');
const userId = String.fromEnvironment('RTC_USER_ID');
const peerId = String.fromEnvironment('RTC_PEER_ID');
const token = String.fromEnvironment('RTC_TOKEN');
const roomId = 'video-test';

void main() => runApp(const MaterialApp(home: VideoCallScreen()));

class VideoCallScreen extends StatefulWidget {
  const VideoCallScreen({super.key});

  @override
  State<VideoCallScreen> createState() => _VideoCallScreenState();
}

class _VideoCallScreenState extends State<VideoCallScreen> {
  final rtc = RTCExpress();
  String status = 'Not connected';
  bool joined = false;
  bool incoming = false;
  bool inCall = false;
  bool connected = false;
  bool muted = false;
  bool cameraOff = false;

  @override
  void initState() {
    super.initState();
    rtc.on('roomJoined', (_) => setState(() {
          joined = true;
          status = 'Joined $roomId';
        }));
    rtc.on('callInvite', (p) => setState(() {
          incoming = true;
          status = 'Incoming ${p['callType']} call';
        }));
    rtc.on('callState', (p) => setState(() {
          final state = p['state'];
          status = 'Call $state';
          inCall = state == 'ringing' || state == 'connecting' || state == 'connected';
          connected = state == 'connected';
          if (state != 'ringing') incoming = false;
          if (!inCall) {
            muted = false;
            cameraOff = false;
          }
        }));
    rtc.on('error', (p) => setState(() => status = 'Error: ${p['message']}'));
  }

  // Ask for the camera and microphone together, right before they are needed.
  Future<bool> askPermissions() async {
    final result = await [Permission.camera, Permission.microphone].request();
    final granted = result.values.every((s) => s.isGranted);
    if (!granted) setState(() => status = 'Allow camera and microphone to make video calls');
    return granted;
  }

  Future<void> connect() async {
    setState(() => status = 'Connecting...');
    await rtc.init(const RTCInitOptions(
      serverUrl: 'https://api.devsquarelabs.com',
      appId: appId,
      userId: userId,
      token: token,
      mediaMode: 'p2p', // 1:1 video goes directly between the two phones
    ));
    await rtc.joinRoom(roomId);
  }

  Future<void> startVideoCall() async {
    if (await askPermissions()) await rtc.callUser(peerId, video: true);
  }

  Future<void> accept() async {
    if (await askPermissions()) await rtc.acceptCall();
  }

  @override
  void dispose() {
    rtc.destroy();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Video call: $userId')),
      body: SafeArea(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            Padding(
              padding: const EdgeInsets.all(12),
              child: Text(status, textAlign: TextAlign.center),
            ),
            Expanded(
              child: connected
                  ? Stack(children: [
                      const Positioned.fill(child: RTCVideoView()), // the other person
                      const Positioned(
                        top: 12,
                        right: 12,
                        width: 110,
                        height: 150,
                        child: RTCVideoView(local: true), // your own camera
                      ),
                    ])
                  : const Center(child: Icon(Icons.videocam, size: 64)),
            ),
            Padding(
              padding: const EdgeInsets.all(16),
              child: Wrap(
                alignment: WrapAlignment.center,
                spacing: 12,
                runSpacing: 8,
                children: [
                  if (!joined)
                    FilledButton(onPressed: connect, child: const Text('Connect and join')),
                  if (joined && !inCall)
                    FilledButton(onPressed: startVideoCall, child: Text('Video call $peerId')),
                  if (incoming) ...[
                    FilledButton(onPressed: accept, child: const Text('Accept')),
                    OutlinedButton(onPressed: rtc.rejectCall, child: const Text('Reject')),
                  ],
                  if (inCall && !incoming) ...[
                    OutlinedButton(
                      onPressed: () {
                        setState(() => muted = !muted);
                        rtc.muteMicrophone(muted);
                      },
                      child: Text(muted ? 'Unmute' : 'Mute'),
                    ),
                    OutlinedButton(
                      onPressed: () {
                        setState(() => cameraOff = !cameraOff);
                        rtc.muteCamera(cameraOff);
                      },
                      child: Text(cameraOff ? 'Camera on' : 'Camera off'),
                    ),
                    OutlinedButton(onPressed: rtc.switchCamera, child: const Text('Flip camera')),
                    FilledButton(onPressed: rtc.endCall, child: const Text('End call')),
                  ],
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

How it works

  • init connects with a short-lived user token. mediaMode: 'p2p' sends video directly between the two phones, which is what RTCVideoView renders. TURN relays are included for networks that block direct connections.
  • joinRoom asks to join. Membership is confirmed by the roomJoined event, so the call button only appears after it fires.
  • callUser(peerId, video: true) rings the other user with a video call. On their phone, callInvite fires with callType: 'video', and they can acceptCall or rejectCall.
  • RTCVideoView() shows the other person; RTCVideoView(local: true) shows your own camera. Both are native Android views, so give them a bounded size (here: full screen plus a 110×150 self-view).
  • muteCamera turns your camera off and on, switchCamera flips between front and back, muteMicrophone mutes audio and endCall hangs up.

5. Create two test tokens

Log in to your customer console → Token tools and create two short-lived tokens in the same project and room:

  • User ID alice, room ID video-test.
  • User ID bob, room ID video-test.
Use user tokens, never your App SecretTest tokens expire, which is what you want. Your App Secret must never be built into a mobile app, because anyone can extract it from the APK.

6. Run it on two phones

List your connected devices with flutter devices. Then start the app on the first phone as Alice:

flutter run -d FIRST_DEVICE_ID --dart-define=RTC_APP_ID=YOUR_APP_ID --dart-define=RTC_USER_ID=alice --dart-define=RTC_PEER_ID=bob --dart-define=RTC_TOKEN=ALICE_TOKEN

In a second terminal, start it on the other phone as Bob:

flutter run -d SECOND_DEVICE_ID --dart-define=RTC_APP_ID=YOUR_APP_ID --dart-define=RTC_USER_ID=bob --dart-define=RTC_PEER_ID=alice --dart-define=RTC_TOKEN=BOB_TOKEN
  1. Press Connect and join on both phones and wait for Joined video-test.
  2. On Alice's phone, press Video call bob and allow camera and microphone access.
  3. On Bob's phone, press Accept and allow access too.
  4. When the status shows Call connected, each phone shows the other person full screen and its own camera in the corner. Try Camera off, Flip camera, Mute and End call.

Two phones next to each other will echo; use headphones, or move apart.

Troubleshooting

  • Error plan_feature_denied when calling: video needs the Pro plan on this project. Check Billing in the console.
  • Build fails with a minSdk error: set minSdk = 24 as in step 3, then run flutter clean.
  • Call connects but the video area is black: check that camera permission was allowed in Android settings, and that no other app is using the camera.
  • UnsupportedError on iOS: RTCVideoView currently supports Android only.
  • Call button never appears: both tokens must be for the same room, video-test, and must not be expired.
  • No incoming call: RTC_PEER_ID must exactly match the other phone's user ID, and that phone must be connected.

7. Before you ship

Replace the --dart-define token with a call to your own backend. Your server signs the user in, checks they may join the room, and requests a short-lived token from POST https://api.devsquarelabs.com/v1/token with your App ID and App Secret; the Node.js server SDK does this in a few lines. The App Secret stays on the server.

Then test across Wi-Fi and mobile data, with denied permissions, a rejected call, an expired token, and a phone that rotates or goes into the background. Video uses far more data than voice, so show the connection state clearly. This tutorial covers foreground 1:1 video; ringing a phone while the app is closed needs push notifications.

Flutter video calling questions

Do I need my own WebRTC, TURN or media server?

No. RTCExpress hosts signaling, STUN, TURN relays and media servers. The Flutter plugin connects to them with the token your backend issues.

How are video minutes counted?

In participant minutes: a two-person video call lasting ten minutes uses twenty. Pro includes 10,000 video minutes and 50,000 voice minutes a month. See pricing.

Can I start with voice and add video later?

Yes. The same plugin does both: callUser(peerId) is a voice call and callUser(peerId, video: true) is a video call. Build the voice version on the Free plan, then switch to Pro when you add video.

Is there a web version?

Yes. The JavaScript video calling tutorial uses the same project, tokens and call flow for browsers.