Search…
Custom Flutter Widgets
Custom Rive Widgets created for Flutter
This is the manual for the old version of Rive (formerly Flare). Visit the Help Center for the new Rive here.

Network Loading in Rive

This Rive example demonstrates how to create a custom class to download a ".flr" file and animate it within Flutter. It downloads the ".flr" file from the network, loads an Actor and instances an Artboard from it.
1
class MyHomePage extends StatelessWidget {
2
...
3
const Flare(
4
filename: "https://cdn.2dimensions.com/Filip.flr",
5
animation: "idle"),
6
),
7
...
Copied!
The Flare widget needs a filename that is passed as a String, which will be the URL for the ".flr" file. It also needs an animation to play that will also be passed as a String.
1
class Flare extends StatefulWidget {
2
final String filename;
3
final String animation;
4
final BoxFit fit;
5
final Alignment alignment;
6
7
const Flare(
8
{Key key,
9
this.filename,
10
this.animation,
11
this.fit = BoxFit.contain,
12
this.alignment = Alignment.center})
13
: super(key: key);
14
15
@override
16
_FlareState createState() => _FlareState();
17
}
18
Copied!
When the widget is initialized it will _load() the flare file from the network, instance the correct Artboard, and use it to display the FlareArtboard widget.
1
Future<void> _load() async {
2
HttpClient client = HttpClient();
3
HttpClientRequest request = await client.getUrl(Uri.parse(widget.filename));
4
HttpClientResponse response = await request.close();
5
var data = await consolidateHttpClientResponseBytes(response);
6
var actor = await FlutterActor.loadFromByteData(ByteData.view(data.buffer));
7
var artboard = actor.artboard;
8
artboard.initializeGraphics();
9
10
var flutterArtboard = artboard.makeInstance() as FlutterActorArtboard;
11
flutterArtboard.initializeGraphics();
12
flutterArtboard.advance(0);
13
14
setState(() {
15
_artboard = flutterArtboard;
16
});
17
}
Copied!
The FlareArtboard widget handles drawing the Artboard once it is loaded from the network.
1
class FlareArtboard extends LeafRenderObjectWidget {
2
final FlutterActorArtboard artboard;
3
final BoxFit fit;
4
final Alignment alignment;
5
final FlareController controller;
6
7
const FlareArtboard(this.artboard,
8
{this.fit = BoxFit.contain,
9
this.alignment = Alignment.center,
10
this.controller});
11
12
@override
13
RenderObject createRenderObject(BuildContext context) {
14
return FlareArtboardRenderObject()
15
..artboard = artboard
16
..fit = fit
17
..controller = controller
18
..alignment = alignment;
19
}
Copied!
Using a very simple custom controller extended from FlareControls allows us to play the default animation on initialization of the loaded Artboard.
1
class SimpleControls extends FlareControls {
2
final String defaultAnimation;
3
SimpleControls(this.defaultAnimation);
4
@override
5
void initialize(FlutterActorArtboard artboard) {
6
super.initialize(artboard);
7
if (defaultAnimation != null) {
8
play(defaultAnimation);
9
}
10
}
11
}
Copied!

More Custom Widgets coming soon...

Last modified 6mo ago