Created
January 2, 2021 18:27
-
-
Save BarryDaBee/c712ae9005b6e41583180b13c4e2774d 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: BouncyBall(), | |
| ), | |
| ); | |
| } | |
| class BouncyBall extends StatefulWidget { | |
| @override | |
| State<BouncyBall> createState() => BouncyBallState(); | |
| } | |
| class BouncyBallState extends State<BouncyBall> with SingleTickerProviderStateMixin{ | |
| AnimationController controller; | |
| Animation animation; | |
| @override | |
| void initState(){ | |
| super.initState(); | |
| controller = AnimationController(duration: Duration(milliseconds: 800), 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: Container( | |
| decoration: BoxDecoration( | |
| shape: BoxShape.circle, | |
| color: Colors.deepOrange[800], | |
| // boxShadow: [ | |
| // BoxShadow( | |
| // color: Colors.black, | |
| // offset: Offset(-2, 2), | |
| // blurRadius: 3 | |
| // ), | |
| // ], | |
| ), | |
| height: 100, | |
| width: 100, | |
| ), | |
| ), | |
| ), | |
| Transform.scale( | |
| scale: 1 - animation.value, | |
| child: Container( | |
| decoration: BoxDecoration( | |
| color: Colors.black12.withOpacity(1 - animation.value), | |
| borderRadius: BorderRadius.all( | |
| Radius.elliptical(100, 10), | |
| ), | |
| ), | |
| width: 100, | |
| height: 10, | |
| ), | |
| ), | |
| SizedBox(height: 20), | |
| Text( | |
| "Loading".padRight("Loading".length + (animation.value * 3).round(), ' .'), | |
| textAlign: TextAlign.start, | |
| style: TextStyle( | |
| color: Colors.deepOrange[800], | |
| fontSize: 15, | |
| fontWeight: FontWeight.bold, | |
| fontStyle: FontStyle.italic, | |
| ), | |
| ), | |
| ], | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment