Skip to content
Limited timeStarter is now $9 a month instead of $20.See plans
charmotion

How to Use Rive Data Binding & ViewModelInstance in Flutter

By the Charmotion team · Updated · How we write guides

Cover illustration for the guide: How to Use Rive Data Binding & ViewModelInstance in Flutter, with Charmotion demo characters

To use Rive data binding in Flutter, bind a ViewModelInstance to the RiveWidgetController, then read and write its typed properties from Dart code. A ViewModel only describes the properties; the instance holds the live values. Since rive 0.15.0, the controller binds default instances when it is constructed, so the main work is choosing which instance to bind.

Key takeaways

  • A ViewModel defines typed properties in the Rive editor; a ViewModelInstance holds the live values your Flutter code reads and writes.
  • Add the rive package with flutter pub add rive, then run dart run rive_native:setup.
  • From rive 0.15.0, RiveWidgetController binds instances in its constructor, and the separate dataBind call is removed.
  • Read and write each property with the accessor for its type, and dispose any instances you create.
  • Rive 0.15.0 needs Flutter 3.32.0 or later (Dart 3.8.0).

What is a ViewModelInstance in Rive?

This guide explains how to use Rive Data Binding ViewModelInstance in Flutter, from adding the runtime to reading and writing live values. It assumes you already have a .riv file with a state machine. If you are new to the format, read Rive State Machine: Inputs, Triggers & Moods first.

Data binding separates two things. A ViewModel is defined in the Rive editor as a named set of typed properties. A ViewModelInstance holds the live values for one copy of that definition. The Flutter data binding page makes the same split: view models describe a set of properties but cannot get or set values themselves. Instances do that, and one ViewModel can have several instances, each with its own values.

Rive view model properties can be Number, String, Boolean, Color, Enum, Trigger, Image, nested View Model or List types. The designer fixes the type, so the Dart code that reads or writes a property has to match it.

View models can be looked up by name, by index, or as the artboard's default. The name lookup uses the exact name the designer gave the view model in the Rive editor, so check the spelling in the editor before you write any Dart.

How do you add Rive to a Flutter project?

Add the rive package from pub.dev. It is published by the verified publisher rive.app and is described as the Flutter runtime for Rive. The package depends on rive_native, which supplies the renderer and the core C++ runtime. The official docs recommend adding rive rather than rive_native directly, because rive provides the user-facing API.

flutter pub add rive
flutter pub get
dart run rive_native:setup

The setup script downloads prebuilt native libraries after flutter pub get. Run dart run rive_native:setup --build instead if you want the libraries compiled locally. Check pub.dev for the current stable version before you pin one. The listing shows 0.14.11 as the latest stable release, with a 0.15.0 prerelease alongside it.

On web, the setup script does not manage the binaries. rive_native loads its WebAssembly module at runtime from Rive's CDN, pinned to the package version, so a web build needs network access to that CDN.

Writing the .riv file that ships in an app needs a free Rive account, according to the pub.dev page. Trying the runtime needs no account. This guide does not state Rive plan prices or limits. For those, read Is Rive free? Pricing, Plans and Commercial Use in 2026.

How do you bind a ViewModelInstance to a RiveWidgetController?

In Flutter, the widget that shows the animation is RiveWidgetBuilder. Its parameters include:

  • stateMachineSelector, which picks the state machine to run.
  • dataBind (optional), which chooses how instances bind.
  • controller (optional), a custom builder for the RiveWidgetController.
  • onLoaded, a callback that runs when the file has loaded.

The official docs show three binding options: DataBind.auto(), DataBind.byName(...) and DataBind.byInstance(...). Use auto when the artboard's default instance is what your screen needs. Use byName or byInstance when your code has to choose which instance the animation reads.

The call you write depends on the version. In 0.14.x code, binding is a separate call on the controller:

// rive 0.14.x
controller.dataBind(DataBind.auto());

In 0.15.0 and later, the separate dataBind call was removed. The RiveWidgetController binds view model instances when it is constructed. The artboard's main view model and every global view model receive default instances unless you pass the main and globals parameters. Flutter 3.32.0 (Dart 3.8.0) is the minimum for 0.15.0.

A ViewModel can also create instances itself: blank, default, by index, or by name. Instances you create this way should be disposed when the widget that uses them no longer needs them. Creating your own instance is useful when two widgets on one screen should show the same character with different values.

How do you read and write properties at runtime?

Once you have an instance, read and write its properties with the accessor that matches each property's type. The Flutter data binding page lists those accessors for each type. Names can change between releases, so check that page for the version you installed: Rive Flutter data binding.

A practical pattern is to keep one instance per screen and push app state into it. For example, a Number property called progress can drive a loading bar inside the animation while your Dart code updates it as a download advances. String, Color and Boolean properties follow the same pattern with their own types.

Triggers behave differently. A trigger fires once and then resets, so use it for a one-off event such as a celebration. Use a Boolean or Number when the state should stay until your code changes it.

Lists are a separate case. A List property holds nested instances, and each item is its own ViewModelInstance that needs its own handling. Start with flat properties, confirm the binding works, and add lists after that.

What changed for data binding in Flutter rive 0.15.0?

If you upgrade from 0.14.x, three things change. The table compares them.

Area0.14.x0.15.0 and later
Binding callcontroller.dataBind(...) after the controller is readyBinding happens when the RiveWidgetController is constructed; the dataBind call is removed
Default instancesSet by the dataBind call or option you passMain and global view models get defaults unless you pass main and globals
Minimum FlutterCheck the 0.14.x listing on pub.devFlutter 3.32.0 (Dart 3.8.0)

The practical step is to search your project for dataBind, remove the calls on 0.15, and pass explicit main and globals values only where you need a specific instance. The Flutter migration guide lists the full set of changes.

Other runtimes change on their own schedules. The Apple runtime began binding authored default instances automatically in v6.28.0, and the Android runtime added font data binding in v11.13.0. Those are separate runtimes, and this guide covers Flutter only. For the Apple side, see Rive Data Binding in SwiftUI (New Apple Runtime).

What are common mistakes with Rive data binding in Flutter?

  • Keeping dataBind after an upgrade. The call no longer exists in 0.15.0. Remove it rather than adding a second bind.
  • Writing to the ViewModel. Properties belong to an instance. Get an instance first, then set values on it.
  • Using the wrong property type. A Number property will not take a String. Match the type the designer chose.
  • Forgetting global view models. Each global view model also gets a default instance. If your app binds a different global instance, pass globals explicitly so you do not read the default by accident.
  • Leaking instances. Dispose the instances you create when the screen closes.
  • Testing one platform only. Web loads the runtime's WebAssembly from a CDN, so test the platforms you ship.

How to use Rive Data Binding ViewModelInstance in Flutter

  1. Add the runtime. Run flutter pub add rive, then flutter pub get and dart run rive_native:setup. Use the --build flag if you want the native libraries compiled locally.
  2. Define the ViewModel in the Rive editor. Create a ViewModel with typed properties such as Number, String, Boolean, Color or Trigger, and make it the artboard's main view model. Note the exact name.
  3. Build the widget. Use RiveWidgetBuilder with a stateMachineSelector and, if needed, a custom controller and an onLoaded callback.
  4. Bind the instance. On rive 0.15.0 and later, the RiveWidgetController binds default instances in its constructor, so no dataBind call is needed. On 0.14.x, call controller.dataBind(DataBind.auto()). Use DataBind.byName or DataBind.byInstance to choose a specific instance.
  5. Read and write typed properties. Set each property through the accessor for its type, as listed on the Flutter data binding page for your version. Use triggers for one-off events and Booleans or Numbers for lasting state.
  6. Dispose instances you create. Dispose any ViewModelInstance you created yourself when the screen or widget that uses it is removed.

Frequently asked questions

Is the Rive Flutter runtime open source?

Rive's runtimes are open source and play any .riv file. An app that only plays and binds a finished file does not need the editor. The editor is where the ViewModel and state machine are built, while the Flutter package is what your app ships with.

Does Rive data binding work on Flutter web?

Flutter web uses rive_native's WebAssembly module, which loads at runtime from Rive's CDN and is pinned to the package version. The setup script does not manage web binaries. Check the Flutter runtime page for which platforms are fully supported, because the pub.dev platform list does not settle every case.

Do I need a Rive account to build an app with Rive in Flutter?

You can try the runtime without an account. The pub.dev page says that writing the .riv file that ships in an app needs a free Rive account. This guide does not state Rive plan prices or limits, so check the official Rive pricing page or the pricing guide linked above before you ship.

Sources

Related guides