Introduction
Rive is a powerful tool for creating interactive vector animations that integrate seamlessly with Flutter. Unlike traditional frame-based approaches, Rive animations are resolution-independent, highly performant, and driven by state machines. In this tutorial, you’ll learn how to embed and control Rive animations in your Flutter app to deliver polished, responsive UI effects.
Integrating Rive into Your Flutter Project
Add the Rive dependency
In your pubspec.yaml, include the Rive package:
dependencies:
flutter:
sdk: flutter
rive: ^0.11.0
assets
Run flutter pub get to install.
Add your .riv file
Drop your exported Rive file (for example, character.riv) into assets/animations/ and declare it under assets.
Import the package
import 'package:rive/rive.dart';
Loading and Controlling Rive Animations
At its simplest, you can render a Rive file as a static animation loop:
import 'package:flutter/material.dart';
import 'package:rive/rive.dart';
class SimpleRiveAnimation extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: RiveAnimation.asset(
'assets/animations/character.riv',
fit: BoxFit.contain,
),
);
}
}This widget auto-plays the default animation in a loop. For finer control, you’ll need a RiveAnimationController.
Advanced Interaction with State Machines
State machines allow you to trigger animations based on boolean, number, or trigger inputs.
In Rive Editor:
• Define a State Machine (e.g., CharacterSM).
• Add inputs: idle, jump, speed.
Attach and control state machine in Flutter:
class StateMachineExample extends StatefulWidget {
@override
_StateMachineExampleState createState() => _StateMachineExampleState();
}
class _StateMachineExampleState extends State<StateMachineExample> {
Artboard? _artboard;
StateMachineController? _controller;
SMIInput<bool>? _jumpInput;
SMIInput<double>? _speedInput;
@override
void initState() {
super.initState();
rootBundle.load('assets/animations/character.riv').then((data) {
final file = RiveFile.import(data);
final artboard = file.mainArtboard;
_controller = StateMachineController.fromArtboard(artboard, 'CharacterSM');
if (_controller != null) {
artboard.addController(_controller!);
_jumpInput = _controller!.findInput<bool>('jump');
_speedInput = _controller!.findInput<double>('speed');
}
setState(() => _artboard = artboard);
});
}
@override
Widget build(BuildContext context) {
return Column(
children: [
Expanded(child: _artboard == null ? Container() : Rive(artboard: _artboard!)),
ElevatedButton(
onPressed: () => _jumpInput?.value = true,
child: Text('Jump'),
),
Slider(
min: 0,
max: 100,
onChanged: (v) => _speedInput?.value = v,
),
],
);
}
}This setup loads the Rive file, locates the state machine, and binds inputs to Flutter widgets. Tapping “Jump” triggers the jump animation, while the slider adjusts speed in real time.
Performance Tips and Best Practices
• Preload large .riv assets before display to avoid jank.
• Reuse controllers when possible; avoid reloading artboards on every rebuild.
• Optimize your Rive file: remove unused nodes and animations.
• Use Const constructors and const widgets around static UI to minimize rebuilds.
• Profile in debug and release modes; Rive offers detailed metrics when you enable performance logs.
Vibe Studio

Vibe Studio, powered by Steve’s advanced AI agents, is a revolutionary no-code, conversational platform that empowers users to quickly and efficiently create full-stack Flutter applications integrated seamlessly with Firebase backend services. Ideal for solo founders, startups, and agile engineering teams, Vibe Studio allows users to visually manage and deploy Flutter apps, greatly accelerating the development process. The intuitive conversational interface simplifies complex development tasks, making app creation accessible even for non-coders.
Conclusion
Animating with Rive in Flutter leverages vector-based art and state machines to create dynamic, interactive UI without sacrificing performance. You’ve seen how to integrate the Rive package, render simple loops, control state machines, and fine-tune performance.