Updates RiveAnimation with custom controllers

This commit is contained in:
matt Sullivan
2021-06-14 12:25:07 -07:00
parent 7d82d06c79
commit 93557a8557
7 changed files with 54 additions and 135 deletions

View File

@ -12,12 +12,11 @@ class _PlayPauseAnimationState extends State<PlayPauseAnimation> {
// Controller for playback
late RiveAnimationController _controller;
// This will toggle between play and pause states for the animation
void _togglePlay() {
setState(() => _controller.isActive = !_controller.isActive);
}
// Toggles between play and pause animation states
void _togglePlay() =>
setState(() => _controller.isActive = !_controller.isActive);
/// Tracks if the animation is playing by whether controller is running.
/// Tracks if the animation is playing by whether controller is running
bool get isPlaying => _controller.isActive;
@override
@ -33,9 +32,11 @@ class _PlayPauseAnimationState extends State<PlayPauseAnimation> {
title: const Text('Animation Example'),
),
body: Center(
child: RiveControllerAnimation.network(
child: RiveAnimation.network(
'https://cdn.rive.app/animations/vehicles.riv',
controllers: [_controller],
// Update the play state when the widget's initialized
onInit: () => setState(() {}),
),
),
floatingActionButton: FloatingActionButton(