Created
June 18, 2021 21:54
-
-
Save mjohnsullivan/f2aa34a89a6777ab3d38540e35947fe9 to your computer and use it in GitHub Desktop.
An example of mixing and controlling multiple animations in Rive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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