Skip to content

Instantly share code, notes, and snippets.

@salihgueler
Created July 14, 2018 19:59
Show Gist options
  • Save salihgueler/ab016f008a6e6f00070f520a6875d264 to your computer and use it in GitHub Desktop.
Save salihgueler/ab016f008a6e6f00070f520a6875d264 to your computer and use it in GitHub Desktop.
Parenting Animation
class ParentingAnimationWidget extends StatefulWidget {
@override
ParentingAnimationWidgetState createState() =>
ParentingAnimationWidgetState();
}
class ParentingAnimationWidgetState extends State<ParentingAnimationWidget>
with TickerProviderStateMixin {
Animation growingAnimation;
Animation animation;
AnimationController controller;
@override
void initState() {
super.initState();
controller = AnimationController(
duration: const Duration(seconds: 2), vsync: this);
growingAnimation = Tween(begin: 10.0, end: 100.0)
.animate(CurvedAnimation(parent: controller, curve: Curves.easeIn));
animation = Tween(begin: -0.25, end: 0.0).animate(CurvedAnimation(
parent: controller,
curve: Curves.easeIn,
))
..addStatusListener((status) {
if (status == AnimationStatus.completed) {
controller.reverse();
}
if (status == AnimationStatus.dismissed) {
Navigator.pop(context);
}
});
}
@override
Widget build(BuildContext context) {
final double width = MediaQuery.of(context).size.width;
controller.forward();
return AnimatedBuilder(
animation: controller,
builder: (BuildContext context, Widget child) {
return new Scaffold(
body: new Align(
alignment: Alignment.center,
child: new Container(
child: new Center(
child:
new ListView(shrinkWrap: true, children: <Widget>[
Transform(
transform: Matrix4.translationValues(
animation.value * width, 0.0, 0.0),
child: Center(
child: AnimatedBuilder(
animation: growingAnimation,
builder: (BuildContext context, Widget child) {
return new Center(
child: Container(
height: growingAnimation.value,
width: growingAnimation.value * 2,
color: Colors.black12,
));
},
))),
Transform(
transform: Matrix4.translationValues(
animation.value * width,
0.0,
0.0,
),
child: new Center(
child: new Container(
padding: const EdgeInsets.only(top: 16.0),
child: Container(
width: 200.0,
height: 100.0,
color: Colors.black12,
),
))),
])))));
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment