Skip to content

Instantly share code, notes, and snippets.

@mhmzdev
Created June 25, 2020 03:08
Show Gist options
  • Save mhmzdev/7ffe5f813747ec3a4bdf9ebf51b2c4e5 to your computer and use it in GitHub Desktop.
Save mhmzdev/7ffe5f813747ec3a4bdf9ebf51b2c4e5 to your computer and use it in GitHub Desktop.
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