flutterOctober 21, 2024

Struggling with Twilio Voice Call Integration in Flutter? twilio_voice_flutter Solves It!

Introduction

The twilio_voice_flutter plugin simplifies integration with Twilio’s Programmable Voice SDK, enabling VoIP calling within your Flutter apps. It supports both iOS and Android, offering an easy-to-use API for managing calls. Ideal for customer service, communication, or any app needing real-time voice, it leverages Twilio’s reliable infrastructure to deliver high-quality VoIP features.

Getting Started

Add the dependency to your pubspec.yaml file and run pub get:

dependencies:
  twilio_voice_flutter: ^0.0.3

Then import the package into your Dart file:

import 'package:twilio_voice_flutter/twilio_voice_flutter.dart';

⚠️ Important Note

This plugin requires Firebase setup for Twilio voice calls. It uses FCM tokens for handling calls on Android 📲 and VoIP notifications for iOS 📞. Ensure both platforms are properly configured for smooth call functionality.

Platform Setup

Android

Open your AndroidManifest.xml file and add the following service declaration inside the tag:


    ...
    
        
            
        
    
    ...

iOS

Open Xcode, go to Signing & Capabilities, and enable the following Background Modes: Audio, AirPlay, and Picture in Picture and Voice over IP. Then add the required keys to your Info.plist:

UIBackgroundModes

    audio
    voip

🔑 Twilio Voice Call Access Token Setup

To generate the access token and enable Twilio calls, follow the steps in the official Twilio repositories:

Setting Up Twilio Token

The setTwilioToken function registers a user’s identity with Twilio Voice using the provided access token. On Android it also retrieves the FCM token from Firebase Cloud Messaging:

static Future setTwilioToken(String identity, String accessToken) async {
  try {
    String accessToken = await _getAccessToken(identity);
    if (Platform.isAndroid) {
      String? fcmToken = await FirebaseMessaging.instance.getToken() ?? "";
      await TwilioVoiceFlutter.register(
          identity: identity, accessToken: accessToken, fcmToken: fcmToken);
    } else {
      await TwilioVoiceFlutter.register(
          identity: identity, accessToken: accessToken, fcmToken: "");
    }
    return true;
  } catch (_) {
    return false;
  }
}

🔗 Visit the example project for more information

Features

1. VoIP Call Management

  • Initiate Calls : Start a VoIP call to any recipient using the makeCall method with custom call data support.
  • Receive Incoming Calls : Handle incoming call invites via push notifications with built-in CallKit support on iOS.
  • Call Status Notifications : Stay updated on ringing, connecting, and disconnecting states via Flutter MethodChannel callbacks.

2. In-Call Controls

  • Mute/Unmute : Toggle mute with toggleMute and check current status with isMuted.
  • Speakerphone Control : Switch between speaker and receiver with toggleSpeaker, verify route with isSpeaker.

3. CallKit Integration for iOS

  • Native CallKit Support : Manages incoming and outgoing VoIP calls with a familiar native UI experience.
  • Background VoIP Support : Receive VoIP calls while the app is in the background via proper background mode configuration.

4. Push Notification Support

  • VoIP Push Notifications : Handle VoIP push via FCM on Android and APNs on iOS.
  • Push Credential Management : Manage device and access tokens for reliable VoIP push delivery.

5. DTMF Signaling

  • Send DTMF Digits : During an active call, send tones using the sendDigits method ideal for automated phone systems.

6. Contact & Data Management

  • Custom Contact Data : Store and retrieve display names and photo URLs to personalize the calling experience.
  • Persistent Token Storage : Securely store access tokens using UserDefaults on iOS to maintain state across sessions.
  • Graceful Error Handling : Token expiration and failed connections are managed and reported to the user effectively.

Function Overview

  • registerTwilio() : Registers the device with Twilio using the access token and device token for VoIP push notifications.
  • unregisterTwilio() : Unregisters the device from Twilio VoIP push notifications.
  • makeCall(String to) : Initiates a voice call to the specified recipient. Returns an error if an active call already exists.
  • toggleMute() : Toggles the mute status of the ongoing call and notifies the Flutter side.
  • isMuted() : Returns the current mute status of the ongoing call.
  • toggleSpeaker() : Toggles speaker mode during an ongoing call and notifies the Flutter side.
  • isSpeaker() : Checks if speaker mode is currently active.
  • hangUp() : Ends the current call and clears call-related data.
  • activeCall() : Returns details of the active call if one exists.
  • sendDigits(String digits) : Sends DTMF digits during an active call.

Conclusion

The twilio_voice_flutter plugin provides a robust and production-ready foundation for integrating real-time voice communication into Flutter apps. With support for VoIP call management, in-call controls, CallKit integration, push notifications, DTMF signaling, and persistent data storage, it covers everything needed for customer support, in-app calling, and beyond.

For full documentation and the example project, check it out on pub.dev.

Keep Reading
Related Articles

You Might Also Like

Is Flutter Good for Business Apps? Pros, Cons and When Not to Use It

Is Flutter Good for Business Apps? Pros, Cons and When Not to Use It

Flutter can cut development cost and speed up launch, but it isn’t right for every business app. Here are the real pros, cons, and the cases where you should skip it.

flutter+3
Nov 2, 2026Read more
FlutterFlow App Events: Complete Guide for Scalable App Development

FlutterFlow App Events: Complete Guide for Scalable App Development

Introduction Building scalable applications in low-code platforms has always been a balance between speed and maintainability. While FlutterFlow makes UI development incredibly fast, managing communication between different parts of an app could sometimes become complex. With the introduction of App Events, FlutterFlow has taken a major step forward bringing cleaner architecture, better performance, and a […]

flutter
Apr 21, 2026Read more
Integrating Tamara Payment Gateway in a FlutterFlow Application

Integrating Tamara Payment Gateway in a FlutterFlow Application

Introduction Integrating a reliable payment gateway is essential for delivering a smooth and secure user experience. Building a payment system isn’t just about processing transactions it’s about ensuring security, reliability, and compliance, all while maintaining a seamless user journey. Here’s how I integrated the Tamara Payment Gateway into a FlutterFlow application, creating a complete end-to-end […]

flutter
Apr 21, 2026Read more
How I Built a Production-Ready AI Chat App in FlutterFlow (With OpenAI + Firebase)

How I Built a Production-Ready AI Chat App in FlutterFlow (With OpenAI + Firebase)

Introduction AI is everywhere in 2026 but building a production-ready AI chat app is still challenging, especially when using low-code tools like FlutterFlow. In this article, I’ll walk you through how I built a scalable AI chat system using FlutterFlow + Firebase + OpenAI API. Architecture Overview Frontend : FlutterFlow UI Backend : Firebase (Firestore […]

flutter
Apr 20, 2026Read more