Skip to main content

Installation

Add the Flutter package from pub.dev:
The package supports iOS and Android Flutter apps.

Import

Initialize

Initialize AvatarKit once before loading avatars or creating an avatar view.
Use DrivingServiceMode.direct for Direct Mode. Use DrivingServiceMode.backend when your Flutter app receives response audio and motion data from Backend Mode Client. initialize fails fast when appID is missing, rather than returning silently. Get an App ID from app.spatius.ai.

Configuration

The audio format is not part of Configuration. Set it per view with AvatarWidget(audioFormat:); see AudioFormat.

RenderQuality

RenderQuality.ultra is the default and highest-quality tier. Use high or standard only when you intentionally trade visual quality for lower rendering cost.

AudioFormat

Each avatar view has its own audio format, so two views in one app can run different sample rates. Pass it to AvatarWidget(audioFormat:) when you create the view; it defaults to 16 kHz PCM. The value is used when the native view is created, so changing the widget property afterwards has no effect. Use AvatarController.setAudioFormat to change it at runtime.
Audio that does not match the declared inputAudioFormat is reported through AvatarController.onError as AvatarError.invalidAudioInput. AudioFormat has value equality and converts with toJson() / AudioFormat.fromJson().

Change the audio format at runtime

Read the format in effect for a view with controller.audioFormat(). It returns the format after the SDK’s normalization, for example 48000 Hz for Opus input.
setAudioFormat({sampleRate, inputAudioFormat, opusBitrate, opusUplinkEnabled}) changes the format of a live view without tearing the SDK down. Every parameter is optional; null keeps the current value.
  • Any change interrupts whatever is playing and, in Direct Mode, disconnects. Call start() again and feed audio in the new format.
  • Switching inputAudioFormat to AudioCodec.opus pins the sample rate at 48000. Switching back to AudioCodec.pcm keeps the current rate unless you pass sampleRate in the same call.
  • Accepted sample rates are 8000, 16000, 22050, 24000, 32000, 44100, and 48000. An unsupported rate, or a sampleRate paired with Opus input, is logged by the SDK and leaves the format unchanged.

Load an avatar

Render and control playback

The Flutter view creates an AvatarController when the platform view is ready. Keep that controller and use it for lifecycle, state, and audio operations.

Render over an Avatar Background

Download the optional 16:9 background from Spatius Studio, add it to your Flutter assets, and declare it in pubspec.yaml.
Place the background and AvatarWidget in the same Stack, with the image first.
For square or portrait display windows, center this 16:9 stage inside a clipped outer widget. See Avatar Background for the shared cropping rules. For Direct Mode audio input, start the connection and send PCM chunks:
For audio source and timing guidance, see Audio. For Backend Mode input, feed the response audio and motion data received from your backend:
The per-call audioFormat parameter of yieldAudioData is deprecated and ignored. The format comes from the view: AvatarWidget.audioFormat, or whatever setAudioFormat last applied. Drop the argument if you still pass it; it will be removed in a future release. The iOS and Android SDKs have already removed theirs.

Demos

Flutter Direct Mode demo

Flutter Backend Mode demo