Created
June 25, 2020 03:08
-
-
Save mhmzdev/7ffe5f813747ec3a4bdf9ebf51b2c4e5 to your computer and use it in GitHub Desktop.
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'; | |
class EntranceFader extends StatefulWidget { | |
final Widget child; | |
final Duration delay; | |
final Duration duration; | |
final Offset offset; | |
const EntranceFader({ | |
Key key, | |
this.child, | |
this.delay = const Duration(milliseconds: 0), | |
this.duration = const Duration(milliseconds: 400), | |
this.offset = const Offset(0.0, 32.0), | |
}) : super(key: key); | |
@override | |
EntranceFaderState createState() { | |
return new EntranceFaderState(); | |
} | |
} | |
class EntranceFaderState extends State<EntranceFader> | |
with SingleTickerProviderStateMixin { | |
AnimationController _controller; | |
Animation _dxAnimation; | |
Animation _dyAnimation; | |
@override | |
void initState() { | |
super.initState(); | |
_controller = AnimationController(vsync: this, duration: widget.duration); | |
_dxAnimation = | |
Tween(begin: widget.offset.dx, end: 0.0).animate(_controller); | |
_dyAnimation = | |
Tween(begin: widget.offset.dy, end: 0.0).animate(_controller); | |
Future.delayed(widget.delay, () { | |
if (this.mounted) { | |
_controller.repeat(); | |
} | |
}); | |
} | |
@override | |
void dispose() { | |
_controller.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return AnimatedBuilder( | |
animation: _controller, | |
builder: (context, child) => Opacity( | |
opacity: _controller.value, | |
child: Transform.translate( | |
offset: Offset(_dxAnimation.value, _dyAnimation.value), | |
child: widget.child, | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment