Real-Time Communication

How to Implement One-to-One Video Calling in Flutter Using Agora RTC

By Pawan Kumawat • Published Feb 10, 2026 • 11 min read

1. Video Calling Architecture

1-on-1 video call interfaces typically follow a picture-in-picture (PiP) layout: the remote participant's video fills the background screen, while the local user's camera preview floats in a smaller draggable or corner-anchored box.

2. Rendering Local & Remote Video Views

Agora RTC Engine for Flutter uses `AgoraVideoView` coupled with `VideoViewController` for rendering stream canvas textures natively:

video_call_screen.dart
import 'package:flutter/material.dart';
import 'package:agora_rtc_engine/agora_rtc_engine.dart';

class VideoCallScreen extends StatefulWidget {
  final String channelName;
  final String token;
  final int localUid;

  const VideoCallScreen({
    Key? key,
    required this.channelName,
    required this.token,
    required this.localUid,
  }) : super(key: key);

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

class _VideoCallScreenState extends State<VideoCallScreen> {
  int? _remoteUid;
  bool _localUserJoined = false;
  bool _isMuted = false;
  late RtcEngine _engine;

  @override
  void initState() {
    super.initState();
    _initAgora();
  }

  Future<void> _initAgora() async {
    _engine = createAgoraRtcEngine();
    await _engine.initialize(const RtcEngineContext(
      appId: 'YOUR_AGORA_APP_ID',
      channelProfile: ChannelProfileType.channelProfileCommunication,
    ));

    _engine.registerEventHandler(
      RtcEngineEventHandler(
        onJoinChannelSuccess: (RtcConnection connection, int elapsed) {
          setState(() { _localUserJoined = true; });
        },
        onUserJoined: (RtcConnection connection, int remoteUid, int elapsed) {
          setState(() { _remoteUid = remoteUid; });
        },
        onUserOffline: (RtcConnection connection, int remoteUid, UserOfflineReasonType reason) {
          setState(() { _remoteUid = null; });
        },
      ),
    );

    await _engine.enableVideo();
    await _engine.startPreview();

    await _engine.joinChannel(
      token: widget.token,
      channelId: widget.channelName,
      uid: widget.localUid,
      options: const ChannelMediaOptions(
        clientRoleType: ClientRoleType.clientRoleBroadcaster,
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [
          // Background: Remote Video Stream
          Center(child: _remoteVideo()),

          // Floating Overlay: Local Camera Preview
          Positioned(
            top: 40,
            right: 20,
            width: 120,
            height: 180,
            child: ClipRRect(
              borderRadius: BorderRadius.circular(12),
              child: _localUserJoined
                  ? AgoraVideoView(
                      controller: VideoViewController(
                        rtcEngine: _engine,
                        canvas: const VideoCanvas(uid: 0),
                      ),
                    )
                  : const CircularProgressIndicator(),
            ),
          ),

          // Bottom Call Control Toolbar
          _buildToolbar(),
        ],
      ),
    );
  }

  Widget _remoteVideo() {
    if (_remoteUid != null) {
      return AgoraVideoView(
        controller: VideoViewController.remote(
          rtcEngine: _engine,
          canvas: VideoCanvas(uid: _remoteUid),
          connection: RtcConnection(channelId: widget.channelName),
        ),
      );
    } else {
      return const Text(
        'Waiting for remote participant...',
        style: TextStyle(color: Colors.grey),
      );
    }
  }

  Widget _buildToolbar() {
    return Alignment.bottomCenter.build(
      child: Container(
        margin: const EdgeInsets.only(bottom: 30),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            // Mute Button
            RawMaterialButton(
              onPressed: () {
                setState(() { _isMuted = !_isMuted; });
                _engine.muteLocalAudioStream(_isMuted);
              },
              shape: const CircleBorder(),
              fillColor: _isMuted ? Colors.blueAccent : Colors.white,
              padding: const EdgeInsets.all(12),
              child: Icon(_isMuted ? Icons.mic_off : Icons.mic, size: 20),
            ),
            // Hangup Button
            RawMaterialButton(
              onPressed: () async {
                await _engine.leaveChannel();
                if (mounted) Navigator.pop(context);
              },
              shape: const CircleBorder(),
              fillColor: Colors.redAccent,
              padding: const EdgeInsets.all(15),
              child: const Icon(Icons.call_end, color: Colors.white, size: 28),
            ),
            // Switch Camera Button
            RawMaterialButton(
              onPressed: () {
                _engine.switchCamera();
              },
              shape: const CircleBorder(),
              fillColor: Colors.white,
              padding: const EdgeInsets.all(12),
              child: const Icon(Icons.switch_camera, size: 20),
            ),
          ],
        ),
      ),
    );
  }

  @override
  void dispose() {
    _engine.release();
    super.dispose();
  }
}

3. In-Call Controls & State Isolation

During active calls, users expect responsive mute, speakerphone, and camera flip controls:

  • `_engine.muteLocalAudioStream(bool)` — Stops audio packet transmission without leaving channel.
  • `_engine.muteLocalVideoStream(bool)` — Pauses local camera feed.
  • `_engine.switchCamera()` — Flips between front and rear hardware camera lenses.

4. Summary

By pairing `VideoViewController` with clean Flutter widget stack layouts, you can implement smooth, responsive 1-on-1 video call interfaces in your application.

← Back to Blog Index