Skip to content

Dzmi3y/LottieStateMachine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

LottieStateMachine

A frame-accurate state machine for managing Lottie animations in Flutter using Enums.

Installation

Add to pubspec.yaml:

dependencies:
  lottie_state_machine:
    git:
      url: https://github.com/Dzmi3y/LottieStateMachine.git
      ref: main

Usage

Run Command: Open the terminal in your project folder and run:

flutter pub get

Quick Start

  1. Define states
enum CatState { idle, walk, jump }
  1. Configure animation
final catAnimation = LottieAnimationData<CatState>(
  src: 'assets/cat.json',
  states: {
    CatState.idle: LottieAnimationState(
      id: CatState.idle,
      startFrame: 0,
      endFrame: 29,
      isLoop: true,
    ),
    CatState.walk: LottieAnimationState(
      id: CatState.walk,
      startFrame: 30,
      endFrame: 59,
      nextStateId: CatState.idle,
    ),
  },
);
  1. Use widget
LottieStateMachineWidget<CatState>(
  data: catAnimation,
  currentStateId: _currentState,
  onAnimationFinished: (state) {
    print('$state completed');
  },
)
  1. Change state
setState(() => _currentState = CatState.walk);

API LottieAnimationState

id - State identifier

startFrame/endFrame - Frame range

nextStateId - Next state (optional)

isLoop - Loop animation (default: false)

speed - Playback speed (default: 1.0)

Requirements

Flutter >= 3.0.0

Dart >= 3.0.0

lottie: ^3.1.0

About

A frame-accurate state machine for managing Lottie animations in Flutter using Enums.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages