Methods

Control your animations programmatically using the DotLottieViewController.

Getting the Controller

Access the controller through the onViewCreated callback:

DotLottieViewController? _controller;
DotLottieView(
source: 'assets/animation.lottie',
sourceType: 'asset',
onViewCreated: (controller) {
_controller = controller;
},
)
// Later, use the controller
await _controller?.play();

Playback Control

Basic playback control methods.

MethodReturnsDescription
play()Future<bool?>Starts playing the animation
pause()Future<bool?>Pauses the animation
stop()Future<bool?>Stops the animation and resets to the beginning

Example

ElevatedButton(
onPressed: () async {
await _controller?.play();
},
child: const Text('Play'),
)
ElevatedButton(
onPressed: () async {
await _controller?.pause();
},
child: const Text('Pause'),
)
ElevatedButton(
onPressed: () async {
await _controller?.stop();
},
child: const Text('Stop'),
)

Animation State Getters

Query the current state of the animation.

MethodReturnsDescription
isPlaying()Future<bool?>Returns whether the animation is currently playing
isPaused()Future<bool?>Returns whether the animation is paused
isStopped()Future<bool?>Returns whether the animation is stopped
isLoaded()Future<bool?>Returns whether the animation has loaded
currentFrame()Future<double?>Gets the current frame number
totalFrames()Future<double?>Gets the total number of frames
currentProgress()Future<double?>Gets the current progress (0.0 to 1.0)
duration()Future<double?>Gets the animation duration in milliseconds
loopCount()Future<int?>Gets the current loop count
speed()Future<double?>Gets the current playback speed
loop()Future<bool?>Gets the loop setting
autoplay()Future<bool?>Gets the autoplay setting
useFrameInterpolation()Future<bool?>Gets the frame interpolation setting
segments()Future<List<double>?>Gets the active segment [start, end]
mode()Future<String?>Gets the current playback mode

Example

// Check if animation is playing
final playing = await _controller?.isPlaying();
if (playing == true) {
print('Animation is playing');
}
// Get current progress
final progress = await _controller?.currentProgress();
print('Progress: ${(progress ?? 0) * 100}%');
// Get animation info
final frames = await _controller?.totalFrames();
final duration = await _controller?.duration();
print('$frames frames, $duration ms');

Animation Control Setters

Modify animation behavior at runtime.

MethodReturnsDescription
setSpeed(double speed)Future<void>Sets the playback speed
setLoop(bool loop)Future<void>Sets whether the animation should loop
setFrame(double frame)Future<bool?>Sets the current frame
setProgress(double progress)Future<bool?>Sets the progress (0.0 to 1.0)
setSegments(double start, double end)Future<void>Sets a segment of the animation to play
setMarker(String marker)Future<void>Sets a marker for playback
setMode(String mode)Future<void>Sets the playback mode
setFrameInterpolation(bool useFrameInterpolation)Future<void>Enables or disables frame interpolation

Example

// Change speed dynamically
Slider(
value: _speed,
min: 0.5,
max: 3.0,
onChanged: (value) {
setState(() => _speed = value);
_controller?.setSpeed(value);
},
)
// Seek to 50% progress
await _controller?.setProgress(0.5);
// Play a specific segment
await _controller?.setSegments(30, 90);
await _controller?.play();
// Change playback mode
await _controller?.setMode('bounce');

Theme Methods

Apply and manage animation themes.

MethodReturnsDescription
setTheme(String themeId)Future<bool?>Applies a theme by ID
setThemeData(String themeData)Future<bool?>Applies a theme using JSON data
resetTheme()Future<bool?>Resets to the default theme
activeThemeId()Future<String?>Gets the currently active theme ID

Example

// Apply a theme
await _controller?.setTheme('darkMode');
// Apply custom theme data
final themeJson = '{"colors":{"primary":"#FF0000"}}';
await _controller?.setThemeData(themeJson);
// Reset to default
await _controller?.resetTheme();
// Check active theme
final theme = await _controller?.activeThemeId();
print('Active theme: $theme');

Animation Loading

Load and manage multiple animations.

MethodReturnsDescription
loadAnimation(String animationId)Future<void>Loads a specific animation by ID
activeAnimationId()Future<String?>Gets the currently active animation ID
markers()Future<List<Map<String, dynamic>>?>Gets all available markers

Example

// Load a specific animation
await _controller?.loadAnimation('animation2');
// Get active animation
final animId = await _controller?.activeAnimationId();
print('Current animation: $animId');
// Get all markers
final markers = await _controller?.markers();
markers?.forEach((marker) {
print('Marker: ${marker['name']} at frame ${marker['time']}');
});

Advanced Features

Advanced control methods.

MethodReturnsDescription
setSlots(String slots)Future<bool?>Sets slot data for dynamic content
resize(int width, int height)Future<void>Resizes the animation viewport
getLayerBounds(String layerName)Future<List<double>?>Gets the bounds of a specific layer
manifest()Future<Map<String, dynamic>?>Gets the animation manifest data

Example

// Resize the animation
await _controller?.resize(800, 600);
// Get layer bounds
final bounds = await _controller?.getLayerBounds('myLayer');
print('Layer bounds: $bounds');
// Get manifest
final manifest = await _controller?.manifest();
print('Animations: ${manifest?['animations']}');

State Machine Methods

Control state machines for interactive animations. See the State Machines Guide for detailed examples.

MethodReturnsDescription
stateMachineLoad(String stateMachineId)Future<bool?>Loads a state machine by ID
stateMachineLoadData(String data)Future<bool?>Loads a state machine from JSON data
stateMachineStart()Future<bool?>Starts the loaded state machine
stateMachineStop()Future<bool?>Stops the state machine
stateMachineFire(String event)Future<void>Fires an event input in the state machine
stateMachineSetNumericInput(String key, double value)Future<bool?>Sets a numeric input value
stateMachineSetStringInput(String key, String value)Future<bool?>Sets a string input value
stateMachineSetBooleanInput(String key, bool value)Future<bool?>Sets a boolean input value
stateMachineGetNumericInput(String key)Future<double?>Gets a numeric input value
stateMachineGetStringInput(String key)Future<String?>Gets a string input value
stateMachineGetBooleanInput(String key)Future<bool?>Gets a boolean input value
stateMachineGetInputs()Future<Map<String, String>?>Gets all input names and their types
stateMachineCurrentState()Future<String?>Gets the current state name
getStateMachine(String id)Future<String?>Gets state machine data by ID

Example

// Load and start a state machine
await _controller?.stateMachineLoad('myStateMachine');
await _controller?.stateMachineStart();
// Set inputs
await _controller?.stateMachineSetBooleanInput('isActive', true);
await _controller?.stateMachineSetNumericInput('speed', 2.0);
// Fire an event
await _controller?.stateMachineFire('buttonPressed');
// Get current state
final state = await _controller?.stateMachineCurrentState();
print('Current state: $state');

Cleanup

MethodReturnsDescription
dispose()Future<void>Disposes of the controller and releases resources

Example

@override
void dispose() {
_controller?.dispose();
super.dispose();
}