RivePanel class

A widget that creates a shared texture to paint multiple RiveWidgets to.

Useful when using Factory.rive. This won't have an effect when using Factory.flutter, and will unnecessarily create a new render texture that won't be used.

Painting multiple RiveWidgets to the same texture can drastically improve performance under certain conditions. Drawing multiple RiveWidgets each to their own texture has a performance cost. The more textures you draw to, the more performance you lose. Additionally, on the web, you are limited to the number of WebGL contexts the browser allows. Drawing to a single texture avoids this limitation.

Wrap your RiveWidgets with a RivePanel to enable this behavior, and set useSharedTexture to true in RiveWidget

Note:

  • There is a memory cost in allocating a larger texture. However, under some conditions, the memory cost might be better, or the same. Benchmarking is recommended.
  • Drawing to the same surface will mean that you cannot interleave drawing commands that Rive performs with that of Flutter. If you need to interleave content, you will need to draw to a separate surface - RivePanel. Or use Factory.flutter - which uses the Flutter rendering pipeline to perform all rendering as a single pass. Benchmarking is recommended - what works for one use case may not work for another.

Example:

class ExampleRivePanel extends StatelessWidget {
  const ExampleRivePanel({super.key});

  @override
  Widget build(BuildContext context) {
    return const RivePanel(
      backgroundColor: Colors.red,
      child: ListViewExample(),
    );
  }
}
class ListViewExample extends StatefulWidget {
 const ListViewExample({super.key});

 @override
 State<ListViewExample> createState() => _ListViewExampleState();
}

class _ListViewExampleState extends State<ListViewExample> {
 late final fileLoader = FileLoader.fromAsset(
   'assets/rating.riv',
   riveFactory: Factory.rive,
 );

 @override
 void dispose() {
   fileLoader.dispose();
   super.dispose();
 }

 @override
 Widget build(BuildContext context) {
   return ListView.builder(
     itemCount: 10,
     itemBuilder: (context, index) {
       return MyRiveWidget(fileLoader: fileLoader);
     },
   );
 }
}
class MyRiveWidget extends StatelessWidget {
 const MyRiveWidget({super.key, required this.fileLoader});
 final FileLoader fileLoader;

 @override
 Widget build(BuildContext context) {
   return RiveWidgetBuilder(
     fileLoader: fileLoader,
     builder: (context, state) => switch (state) {
       RiveLoading() => const Center(
           child: Center(child: CircularProgressIndicator()),
         ),
       RiveFailed() => ErrorWidget.withDetails(
           message: state.error.toString(),
           error: FlutterError(state.error.toString()),
         ),
       RiveLoaded() => RiveWidget(
           controller: state.controller,
           fit: Fit.contain,

           /// Set this to true to draw to the nearest `RivePanel`
           useSharedTexture: true,
         )
     },
   );
 }
}

EXPERIMENTAL: This API may change or be removed in a future release.

Inheritance
Annotations
  • @experimental

Constructors

RivePanel({Key? key, Color backgroundColor = Colors.transparent, required Widget child})
const

Properties

backgroundColor Color
final
child Widget
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<RivePanel>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited