A Pen by Geeky-Star on CodePen.
Created
July 17, 2020 15:28
-
-
Save Geeky-star/351a7f0f60a20eb15b71e58dacdb3d97 to your computer and use it in GitHub Desktop.
Ball Animation
This file contains 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(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: AnimationScreen(), | |
); | |
} | |
} | |
class AnimationScreen extends StatefulWidget{ | |
@override | |
_AnimationScreenState createState() => _AnimationScreenState(); | |
} | |
class _AnimationScreenState extends State<AnimationScreen> with SingleTickerProviderStateMixin{ | |
AnimationController _animationController; | |
double currentValue; | |
Animation curveAnimation; | |
@override | |
void initState() { | |
super.initState(); | |
_animationController = AnimationController( | |
duration: Duration(seconds: 6), | |
vsync: this | |
); | |
curveAnimation = CurvedAnimation(parent: _animationController, curve:Curves.elasticOut); | |
_animationController.addListener((){ | |
setState(() { | |
currentValue = _animationController.value; | |
}); | |
}); | |
_animationController.repeat(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("Ball Jumping") | |
), | |
body:Stack( | |
children: <Widget>[ | |
PositionedTransition( | |
child: Container( | |
width: 1, | |
height: 1, | |
decoration: BoxDecoration( | |
color: Colors.red, | |
shape: BoxShape.circle | |
), | |
), | |
rect: RelativeRectTween(begin: RelativeRect.fromLTRB(0, 0, 0, 600), | |
end: RelativeRect.fromLTRB(600,100,0,0),).animate(curveAnimation), | |
) | |
], | |
), | |
floatingActionButton: FloatingActionButton( | |
child: Icon(Icons.book), | |
onPressed: (){ | |
if(_animationController.isAnimating){ | |
_animationController.stop(); | |
}else{ | |
_animationController.repeat(); | |
} | |
}, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment