Skip to content

Instantly share code, notes, and snippets.

@BarryDaBee
Created January 2, 2021 12:02
Show Gist options
  • Select an option

  • Save BarryDaBee/2101a59fe1b3fb4cca6553d0edcb92f4 to your computer and use it in GitHub Desktop.

Select an option

Save BarryDaBee/2101a59fe1b3fb4cca6553d0edcb92f4 to your computer and use it in GitHub Desktop.
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