60 lines
1.4 KiB
Dart
60 lines
1.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
class FadeInUp extends StatefulWidget {
|
|
final Widget child;
|
|
final int delay;
|
|
|
|
const FadeInUp({super.key, required this.child, this.delay = 0});
|
|
|
|
@override
|
|
State<FadeInUp> createState() => _FadeInUpState();
|
|
}
|
|
|
|
class _FadeInUpState extends State<FadeInUp> with SingleTickerProviderStateMixin {
|
|
late AnimationController _controller;
|
|
late Animation<double> _opacity;
|
|
late Animation<Offset> _slide;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_controller = AnimationController(
|
|
vsync: this,
|
|
duration: const Duration(milliseconds: 600),
|
|
);
|
|
|
|
_opacity = Tween<double>(begin: 0, end: 1).animate(
|
|
CurvedAnimation(parent: _controller, curve: Curves.easeOut),
|
|
);
|
|
|
|
_slide = Tween<Offset>(begin: const Offset(0, 0.2), end: Offset.zero).animate(
|
|
CurvedAnimation(parent: _controller, curve: Curves.easeOutCubic),
|
|
);
|
|
|
|
if (widget.delay > 0) {
|
|
Future.delayed(Duration(milliseconds: widget.delay), () {
|
|
if (mounted) _controller.forward();
|
|
});
|
|
} else {
|
|
_controller.forward();
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return FadeTransition(
|
|
opacity: _opacity,
|
|
child: SlideTransition(
|
|
position: _slide,
|
|
child: widget.child,
|
|
),
|
|
);
|
|
}
|
|
}
|