dotLottie Flutter

May 21, 2026 ยท View on GitHub

A Flutter plugin for rendering Lottie and dotLottie animations with full playback control, state machine support, and cross-platform compatibility.

Platforms supported: iOS, Android, macOS, Web, Windows, and Linux

Built on top of native implementations:

Features

  • โœจ Play Lottie and dotLottie animations
  • ๐ŸŽฎ Full playback control (play, pause, stop, seek)
  • ๐Ÿ”„ State machine support with interactive inputs
  • ๐ŸŽจ Theme support
  • ๐Ÿ“ฑ Cross-platform: iOS, Android, macOS, Web, Windows, and Linux

Table of Contents

Installation

With Flutter:

flutter pub add dotlottie-flutter

This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get)

Import it in your Dart code:

import 'package:dotlottie_flutter/dotlottie_flutter.dart';

Android

To allow dotlottie-android to download, ensure you have jitpack inside your build.gradle.kts file:

maven { url = uri("https://jitpack.io") }

Windows

The Windows renderer uses the pre-built dotlottie_player.dll bundled with the plugin (x86_64 and ARM64 are both included). No additional setup is required โ€” Flutter's cmake build copies the DLL into your app bundle automatically.

Linux

The Linux renderer uses the pre-built libdotlottie_rs.so bundled with the plugin (x86_64 and ARM64 are both included). No additional setup is required โ€” Flutter's cmake build copies the shared library into your app bundle automatically.

Ubuntu 24.04 note: If you are using clang 18 from the LLVM apt repository and encounter a type_traits build error, install libc++-dev:

sudo apt-get install libc++-dev libc++abi-dev

Quick Start

import 'package:flutter/material.dart';
import 'package:dotlottie_flutter/dotlottie_flutter.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  DotLottieViewController? _controller;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('dotLottie Example')),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              // DotLottie animation view
              SizedBox(
                width: 300,
                height: 300,
                child: DotLottieView(
                  sourceType: 'url',
                  source: 'https://lottie.host/your-animation.lottie',
                  autoplay: true,
                  loop: true,
                  onViewCreated: (controller) {
                    _controller = controller;
                  },
                  onLoad: () {
                     // Do something
                  }
                ),
              ),
              
              const SizedBox(height: 20),
              
              // Basic playback controls
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  ElevatedButton(
                    onPressed: () => _controller?.play(),
                    child: const Text('Play'),
                  ),
                  const SizedBox(width: 10),
                  ElevatedButton(
                    onPressed: () => _controller?.pause(),
                    child: const Text('Pause'),
                  ),
                  const SizedBox(width: 10),
                  ElevatedButton(
                    onPressed: () => _controller?.stop(),
                    child: const Text('Stop'),
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Properties

Required Properties

PropertyTypeDescription
sourceStringThe source of the animation (URL, asset path, or JSON string)
sourceTypeStringType of source: 'url', 'asset', or 'json'

Playback Properties

PropertyTypeDefaultDescription
autoplayboolfalseWhether the animation should start playing automatically
loopboolfalseWhether the animation should loop
loopCountint?nullNumber of times to loop (overrides loop if set)
speeddouble1.0Playback speed multiplier (e.g., 2.0 for double speed)
modeString?nullPlayback mode: 'forward', 'reverse', 'bounce', or 'reverse-bounce'
useFrameInterpolationboolfalseEnable frame interpolation for smoother playback

Animation Control

PropertyTypeDescription
segmentList<double>?Play a specific segment [startFrame, endFrame]
markerString?Play from a named marker defined in the animation
animationIdString?ID of a specific animation to play (for multi-animation files)

Visual Properties

PropertyTypeDescription
backgroundColorString?Background color in hex format (e.g., '#FF0000')
widthdouble?Canvas width for rendering
heightdouble?Canvas height for rendering

Advanced Properties

PropertyTypeDescription
themeIdString?ID of a theme to apply to the animation
stateMachineIdString?ID of a state machine to load and start automatically

Example Usage

DotLottieView(
  source: 'https://lottie.host/your-animation.lottie',
  sourceType: 'url',
  autoplay: true,
  loop: true,
  speed: 1.5,
  mode: 'bounce',
  backgroundColor: '#FFFFFF',
  useFrameInterpolation: true,
  onViewCreated: (controller) {
    // Access controller for programmatic control
  },
)

State Machine Example

DotLottieView(
  source: 'https://lottie.host/your-animation.lottie',
  sourceType: 'url',
  stateMachineId: 'myStateMachine',
  onViewCreated: (controller) {
    _controller = controller;
  },
  stateMachineOnStateEntered: (state) {
    print('Entered state: $state');
  },
)

// Interact with the state machine
ElevatedButton(
  onPressed: () {
    _controller?.stateMachineSetBooleanInput('isActive', true);
    _controller?.stateMachineFire('myEvent');
  },
  child: Text('Trigger Event'),
)

Methods

Access these methods via the controller:

DotLottieViewController? _controller;
await _controller?.play();

Playback Control

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.

Animation State Getters

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.

Animation Control Setters

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.

Theme Methods

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.

Animation Loading

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.

Advanced Features

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.

State Machine Methods

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 a named event 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.

Cleanup

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

Events

Add listeners to events on the widget:

DotLottieView(
   onFrame: (frameNo) {
      // Do something
   }
)
EventDescription
onLoad โ†’ void Function()?Called when the animation is loaded.
onComplete โ†’ void Function()?Called when the animation completes.
onLoadError โ†’ void Function()?Called when there's an error loading the animation.
onPlay โ†’ void Function()?Called when the animation starts playing.
onPause โ†’ void Function()?Called when the animation is paused.
onStop โ†’ void Function()?Called when the animation is stopped.
onLoop โ†’ void Function(double loopCount)?Called when the animation loops, with the current loop count.
onFrame โ†’ void Function(double frameNo)?Called on each frame update.
onRender โ†’ void Function(double frameNo)?Called when a frame is rendered.
onFreeze โ†’ void Function()?Called when the animation is frozen.
onUnFreeze โ†’ void Function()?Called when the animation is unfrozen.
onDestroy โ†’ void Function()?Called when the animation is destroyed.

State Machine Events

EventDescription
stateMachineOnStart โ†’ void Function()?Called when the state machine starts.
stateMachineOnStop โ†’ void Function()?Called when the state machine stops.
stateMachineOnStateEntered โ†’ void Function(String enteringState)?Called when entering a new state.
stateMachineOnStateExit โ†’ void Function(String leavingState)?Called when exiting a state.
stateMachineOnTransition โ†’ void Function(String previousState, String newState)?Called during a state transition.
stateMachineOnBooleanInputValueChange โ†’ void Function(String inputName, bool oldValue, bool newValue)?Called when a boolean input changes.
stateMachineOnNumericInputValueChange โ†’ void Function(String inputName, double oldValue, double newValue)?Called when a numeric input changes.
stateMachineOnStringInputValueChange โ†’ void Function(String inputName, String oldValue, String newValue)?Called when a string input changes.
stateMachineOnInputFired โ†’ void Function(String inputName)?Called when an input event is fired.
stateMachineOnCustomEvent โ†’ void Function(String message)?Called when a custom state machine event occurs.
stateMachineOnError โ†’ void Function(String message)?Called when a state machine error occurs.

Platform Notes

Windows & Linux

The Windows and Linux implementations use dotlottie-rs via Dart FFI and render directly into a Flutter texture. The following features are supported:

FeatureSupported
Play / Pause / Stopโœ…
Seek (setFrame, setProgress)โœ…
Loop, Speed, Mode, Frame interpolationโœ…
Load from URL, asset, or JSONโœ…
onLoad, onPlay, onPause, onStop, onComplete, onLoop, onFrame, onRenderโœ…
Themesโœ…
Markers / Segmentsโœ…
Multi-animation manifestโœ…
State machinesโŒ

Contributing

See the development guide to learn how to get up and running with this project. Once you're ready, please submit a pull request and we will review it! Thanks!

License

MIT