Skip to main content

Flutter quickstart

Get started with LiveKit and Flutter

Voice AI quickstart

To build your first voice AI app for Flutter, use the following quickstart and the starter app. Otherwise follow the getting started guide below.

Getting started guide

This guide covers the basic setup for a new Flutter app for iOS, Android, or web using LiveKit.

Install LiveKit SDK

flutter pub add livekit_client

Permissions and entitlements

You'll need to request camera and/or microphone permissions (depending on your use case). This must be done within your platform-specific code:

Camera and microphone usage need to be declared in your Info.plist file.

<dict>
...
<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) uses your camera</string>
<key>NSMicrophoneUsageDescription</key>
<string>$(PRODUCT_NAME) uses your microphone</string>
...
</dict>

Your application can still run a voice call when it is switched to the background if the background mode is enabled. Select the app target in Xcode, click the Capabilities tab, enable Background Modes, and check Audio, AirPlay, and Picture in Picture.

Your Info.plist should have the following entries:

<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>

(LiveKit strongly recommends using Flutter 3.3.0+. If you are using Flutter 3.0.0 or below, please see this note in the SDK README.)

Permissions are configured in AppManifest.xml. In addition to camera and microphone, you may need to add networking and bluetooth permissions.

<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />

Add the following entries to your macos/Runner/Info.plist:

<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) uses your camera</string>
<key>NSMicrophoneUsageDescription</key>
<string>$(PRODUCT_NAME) uses your microphone</string>

You might also need the following entitlements, for both DebugProfile.entitlements and Release.entitlements (in macos/Runner/):

<key>com.apple.security.device.camera</key>
<true/>
<key>com.apple.security.device.microphone</key>
<true/>
<key>com.apple.security.device.audio-input</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.network.server</key>
<true/>

On Windows, Visual Studio 2019 is required (note that the link in Flutter docs may download VS 2022).

Add the following permissions to your web/index.html file:

<meta name="permissions-policy" content="interest-cohort=(), microphone=*, camera=*">

Connect to LiveKit

Add the following code to connect and publish audio/video to a room:

final roomOptions = RoomOptions(
adaptiveStream: true,
dynacast: true,
// ... your room options
)
final room = Room();
await room.connect(url, token, roomOptions: roomOptions);
try {
// video will fail when running in ios simulator
await room.localParticipant.setCameraEnabled(true);
} catch (error) {
print('Could not publish video, error: $error');
}
await room.localParticipant.setMicrophoneEnabled(true);

Next steps

The following resources are useful for getting started with LiveKit on Android.

Generating tokens

Guide to generating authentication tokens for your users.