Created
January 2, 2021 12:02
-
-
Save BarryDaBee/2101a59fe1b3fb4cca6553d0edcb92f4 to your computer and use it in GitHub Desktop.
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'; | |
| void main() { | |
| runApp( | |
| MaterialApp( | |
| home: BouncyBallClone(), | |
| ), | |
| ); | |
| } | |
| class BouncyBallClone extends StatefulWidget { | |
| @override | |
| State<BouncyBallClone> createState() => BouncyBallCloneState(); | |
| } | |
| class BouncyBallCloneState extends State<BouncyBallClone> with SingleTickerProviderStateMixin{ | |
| AnimationController controller; | |
| Animation animation; | |
| @override | |
| void initState(){ | |
| super.initState(); | |
| controller = AnimationController(duration: Duration(seconds: 1), vsync: this); | |
| controller.repeat(reverse: true); | |
| animation = CurvedAnimation(parent: controller, curve: Curves.decelerate); | |
| controller.forward().whenComplete(()=>controller.repeat(reverse: true),); | |
| animation.addListener(()=>setState((){})); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| body: Column( | |
| mainAxisAlignment: MainAxisAlignment.center, | |
| children: [ | |
| Center( | |
| child: Transform.translate( | |
| offset: Offset(0, animation.value * -200), | |
| child: CircleAvatar( | |
| backgroundColor: Colors.blue, | |
| radius: 50, | |
| ), | |
| ), | |
| ), | |
| Transform.scale( | |
| scale: 1 - animation.value, | |
| child: Container( | |
| width: 100, | |
| height: 20, | |
| color: Colors.black | |
| ), | |
| ), | |
| ], | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment