Flutter runtime for Rive.
Add the Rive package dependency
Import the Rive package
Initialize Rive
RiveNative.init
at the start of your app, or before you use Rive. For example, in main.dart
:Add a Rive widget
RiveWidget
, and optionally the RiveWidgetBuilder
.RiveWidgetBuilder
handles file loading, error states, and resource management automatically.RiveWidget
is responsible for rendering the graphic and exposing common view configuration.Loading from different sources
pubspec.yaml
:RiveWidget
RiveWidget
is responsible for displaying Rive graphics.
Properties:
controller
[required]: The RiveWidgetController
that manages the Rive graphicfit
: How the artboard should fit within the widget (default: contain
)alignment
: How the artboard should be aligned within the widget (default: center
)hitTestBehavior
: How pointer events should be handled (default: opaque
)cursor
: The cursor to display when hovering over the widget (default: defer
)layoutScaleFactor
: Scale factor when using Fit.layout
(default: 1.0
)RiveWidgetBuilder
RiveWidgetBuilder
is a higher-level widget that handles file loading, error states, and resource management automatically.
Properties:
fileLoader
[required]: The FileLoader
for loading the Rive filebuilder
[required]: Function that builds the widget based on stateartboardSelector
: Which artboard to use (default: ArtboardDefault()
)stateMachineSelector
: Which state machine to use (default: StateMachineDefault()
)dataBind
: How to bind view model data (optional)controller
: Optional custom controller builderonLoaded
: Callback when Rive state is loadedonFailed
: Callback when Rive state fails to loadRiveWidgetController
RiveWidgetController
manages the graphic.
Creating a Controller:
FileLoader
class provides a unified way to load Rive files from different sources.
Loading from Assets:
File
class:
RiveFileLoaderException
: Thrown when file loading failsRiveArtboardException
: Thrown when artboard selection failsRiveStateMachineException
: Thrown when state machine selection failsRiveDataBindException
: Thrown when data binding failsRiveWidget
)RiveWidget
directly, you are responsible for managing all resources:
RiveWidgetBuilder
)RiveWidgetBuilder
, the widget automatically manages most resources. You only need to dispose the file loader:
RiveWidgetBuilder
, you will not be able to access the RiveWidgetController
(and other state) after the widget is disposed. If you need to access the controller after the widget is disposed, consider creating the file and controller yourself.The exception to this is the FileLoader
, which you control. This loader can be reused across multiple RiveWidgetBuilder
instances. The underlying File
will only be loaded once. The File
will be disposed when the FileLoader
is disposed.File
or FileLoader
, you need to specify a factory to use:
Factory.rive
for the Rive rendererFactory.flutter
for the Flutter renderer (Skia or Impeller)Factory.flutter
to reduce the native overhead of allocating native render targets and textures.Factory.rive
to take advantage of the Rive renderer’s optimizations.Factory.rive
, so if you need that feature, use the Rive renderer.RiveNative.init()
before using any Rive features.pubspec.yaml
and exist in the specified paths.RiveWidgetBuilder
, ensure you handle all possible states (loading, loaded, failed) in the builder function.pubspec.yaml
.flutter pub get
to fetch the latest dependencies.rive_native
plugin.
However, if you need to manually build the native libraries, see the build section in the Rive Native documentation.