Skip to main content
You can manage advancing and drawing an artboard yourself by using a CustomPainter. This will give you more control at a painting level, allowing you to:
  • Draw multiple Rive artboards to the same Flutter Canvas.
  • Advance an artboard manually and control the elapsed time.
  • Reuse the same artboard instance and redraw it multiple times.
  • More complex clipping, transformation, or other painting/rendering can be applied to the canvas.
The Flame game engine makes use of the techniques discussed below to render Rive animations. Some of the code in this example is taken from the flame_rive package.
Note that this is a low-level API, and under most circumstances, it is preferable to make use of theRiveAnimation or Rive widgets instead.

Example Code

The following is a complete example demonstrating how to manually advance a single artboard and draw it multiple times in a grid to the same Flutter canvas. See the online IDE example to run it directly. Image
The RiveArtboardRenderer class is taken from the Flame Rive package, and can be used as a starting point to understand how Rive uses Alignment and BoxFit to layout an artboard to a canvas. The important steps are:
  1. Access an artboard from a RiveFile and attach any Rive animation controller (StateMachineController). The animation can be controlled as it normally would with the controller.
  2. Create a Flutter CustomPaint widget to get access to a Flutter canvas.
  3. Make use of an AnimationController (or Ticker/Listener) to force the RiveCustomPainter to repaint each frame.
  4. Calculate the elapsed time between animation ticks.
  5. Advance the artboard with artboard.advance(dt, nested: true); where dt is the elapsed time (delta time).
  6. Draw the artboard to the canvas with artboard.draw(canvas);
The rest of the code is responsible for layout and sizing.

Other Examples

In this example a single artboard is used, however, it’s possible to draw multiple artboard instances (from the same or different Rive file) to the same canvas. See this editable example that showcases how to draw two different artboards (a unique artboard instance is created for each zombie) to the same canvas. Each artboard has a number input to switch between different skins: Rive Flutter Custom Painter - Multiple Artboards: Image
Note that .instance() is called on the artboard to create a unique instance that can be advanced on its own.