Skip to content

Instantly share code, notes, and snippets.

@acromondx
Created May 11, 2023 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acromondx/dd8da52683dda195cfcee3ec921fc431 to your computer and use it in GitHub Desktop.
Save acromondx/dd8da52683dda195cfcee3ec921fc431 to your computer and use it in GitHub Desktop.
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