58 lines
1.4 KiB
Dart
58 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> _fadeAnimation;
|
|
late Animation<Offset> _slideAnimation;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_controller = AnimationController(
|
|
vsync: this,
|
|
duration: const Duration(milliseconds: 600),
|
|
);
|
|
|
|
_fadeAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(
|
|
CurvedAnimation(parent: _controller, curve: Curves.easeOut),
|
|
);
|
|
|
|
_slideAnimation = Tween<Offset>(begin: const Offset(0, 0.2), end: Offset.zero).animate(
|
|
CurvedAnimation(parent: _controller, curve: Curves.easeOut),
|
|
);
|
|
|
|
Future.delayed(Duration(milliseconds: widget.delay), () {
|
|
if (mounted) {
|
|
_controller.forward();
|
|
}
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return FadeTransition(
|
|
opacity: _fadeAnimation,
|
|
child: SlideTransition(
|
|
position: _slideAnimation,
|
|
child: widget.child,
|
|
),
|
|
);
|
|
}
|
|
}
|