Updated example and readme

This commit is contained in:
Matt Sullivan
2020-11-10 14:46:53 -08:00
parent 3413dc5fe5
commit d0df759001
5 changed files with 153 additions and 55 deletions

View File

@ -2,9 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:rive/rive.dart';
void main() {
runApp(MyApp());
}
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
@ -32,8 +30,7 @@ class _MyHomePageState extends State<MyHomePage> {
setState(() => _controller.isActive = !_controller.isActive);
}
/// We track if the animation is playing by whether or not the controller is
/// running.
/// Tracks if the animation is playing by whether controller is running.
bool get isPlaying => _controller?.isActive ?? false;
Artboard _riveArtboard;
@ -46,19 +43,16 @@ class _MyHomePageState extends State<MyHomePage> {
// download this. The RiveFile just expects a list of bytes.
rootBundle.load('assets/off_road_car.riv').then(
(data) async {
var file = RiveFile();
final file = RiveFile();
// Load the RiveFile from the binary data.
var success = file.import(data);
if (success) {
// The artboard is the root of the animation and is what gets drawn
// into the Rive widget.
var artboard = file.mainArtboard;
if (file.import(data)) {
// The artboard is the root of the animation and gets drawn in the
// Rive widget.
final artboard = file.mainArtboard;
// Add a controller to play back a known animation on the main/default
// artboard.We store a reference to it so we can toggle playback.
artboard.addController(
_controller = SimpleAnimation('idle'),
);
artboard.addController(_controller = SimpleAnimation('idle'));
setState(() => _riveArtboard = artboard);
}
},