From f635df038a76ed3b6af185741b3a977a13574288 Mon Sep 17 00:00:00 2001 From: Muhammad Hamza Date: Sun, 10 Oct 2021 16:30:14 +0500 Subject: [PATCH] new animation added --- .../lib/animations/entrance_fader.dart | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 packages/simplex_app/lib/animations/entrance_fader.dart diff --git a/packages/simplex_app/lib/animations/entrance_fader.dart b/packages/simplex_app/lib/animations/entrance_fader.dart new file mode 100644 index 000000000..4ddcd52c3 --- /dev/null +++ b/packages/simplex_app/lib/animations/entrance_fader.dart @@ -0,0 +1,70 @@ +import 'package:flutter/material.dart'; + +class EntranceFader extends StatefulWidget { + /// Child to be animated on entrance + final Widget? child; + + /// Delay after which the animation will start + final Duration delay; + + /// Duration of entrance animation + final Duration duration; + + /// Starting point from which the widget will fade to its default position + 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 EntranceFaderState(); + } +} + +class EntranceFaderState extends State + 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 (mounted) { + _controller!.forward(); + } + }); + } + + @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, + ), + ), + ); + } +}