Skip to content

Instantly share code, notes, and snippets.

@mjohnsullivan
Created June 18, 2021 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjohnsullivan/f2aa34a89a6777ab3d38540e35947fe9 to your computer and use it in GitHub Desktop.
Save mjohnsullivan/f2aa34a89a6777ab3d38540e35947fe9 to your computer and use it in GitHub Desktop.
An example of mixing and controlling multiple animations in Rive
import 'package:flutter/material.dart';
import 'package:rive/rive.dart';
void main() => runApp(MaterialApp(
home: BouncyTruckAnimation(),
));
class BouncyTruckAnimation extends StatefulWidget {
const BouncyTruckAnimation({Key? key}) : super(key: key);
@override
_BouncyTruckAnimationState createState() => _BouncyTruckAnimationState();
}
class _BouncyTruckAnimationState extends State<BouncyTruckAnimation> {
late RiveAnimationController _controller;
@override
void initState() {
super.initState();
_controller = OneShotAnimation('bounce', autoplay: false);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: GestureDetector(
onTap: () => _controller.isActive = true,
child: RiveAnimation.network(
'https://cdn.rive.app/animations/vehicles.riv',
animations: const ['idle', 'curves'],
controllers: [_controller],
fit: BoxFit.cover,
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment