Created
May 11, 2023 18:17
-
-
Save acromondx/dd8da52683dda195cfcee3ec921fc431 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 FadeInWidget extends StatefulWidget { | |
Widget? child; | |
final Duration duration; | |
FadeInWidget( | |
{super.key, | |
this.child, | |
this.duration = const Duration(milliseconds: 50)}); | |
@override | |
State<FadeInWidget> createState() => _FadeInWidgetState(); | |
} | |
class _FadeInWidgetState extends State<FadeInWidget> | |
with SingleTickerProviderStateMixin { | |
late AnimationController _controller; | |
late Animation<double> _animation; | |
@override | |
void initState() { | |
super.initState(); | |
_controller = AnimationController(duration: widget.duration, vsync: this); | |
_animation = Tween<double>(begin: 0.0, end: 1.0).animate(_controller); | |
_controller.forward(); | |
} | |
@override | |
void dispose() { | |
_controller.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return AnimatedOpacity( | |
duration: widget.duration, | |
opacity: _animation.value, | |
child: widget.child, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment