Skip to content

Instantly share code, notes, and snippets.

@gucci-ninja
Created June 1, 2022 03:19
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 gucci-ninja/4698166233ab078a2ff979b45a4673bb to your computer and use it in GitHub Desktop.
Save gucci-ninja/4698166233ab078a2ff979b45a4673bb to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:rive/rive.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const BasketBallAnimation(),
);
}
}
class BasketBallAnimation extends StatefulWidget {
const BasketBallAnimation({Key? key}) : super(key: key);
@override
State<BasketBallAnimation> createState() => _BasketBallAnimationState();
}
class _BasketBallAnimationState extends State<BasketBallAnimation> {
late RiveAnimationController _controller;
bool get isPlaying => _controller.isActive;
void _toggleAnimation() {
setState(() {
_controller.isActive = !_controller.isActive;
});
}
@override
void initState() {
super.initState();
_controller = SimpleAnimation('idle');
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: RiveAnimation.asset('animations/basketball.riv',
controllers: [_controller])),
floatingActionButton: FloatingActionButton(
onPressed: _toggleAnimation,
tooltip: isPlaying ? 'Pause' : 'Play',
child: Icon(
isPlaying ? Icons.pause : Icons.play_arrow,
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment