Files
CheckTheethKids/lib/screens/hello_splash_screen.dart
Carlos Correia a8af2c6845 CKT String|Colors
2026-07-15 19:13:15 +01:00

109 lines
2.8 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import '../colors/app_colors.dart';
import '../strings/splash_strings.dart';
class HelloSplashScreen extends StatefulWidget {
const HelloSplashScreen({super.key, required this.onFinished, this.duration = const Duration(seconds: 5)});
final Duration duration;
final VoidCallback onFinished;
@override
State<HelloSplashScreen> createState() => _HelloSplashScreenState();
}
class _HelloSplashScreenState extends State<HelloSplashScreen> with TickerProviderStateMixin {
late final AnimationController _controller;
late final Animation<double> _opacity;
late final AnimationController _popController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 700),
);
late final Animation<double> _pop = CurvedAnimation(
parent: _popController,
curve: Curves.elasticOut,
);
Timer? _fadeTimer;
Timer? _doneTimer;
@override
void initState() {
super.initState();
_controller = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 500),
);
_opacity = CurvedAnimation(
parent: _controller,
curve: Curves.easeInOut,
);
_controller.value = 1.0;
_popController.forward();
final int fadeMs = (widget.duration.inMilliseconds - 500).clamp(0, widget.duration.inMilliseconds);
_fadeTimer = Timer(Duration(milliseconds: fadeMs), () {
if (!mounted) return;
_controller.reverse();
});
_doneTimer = Timer(widget.duration, () {
if (!mounted) return;
widget.onFinished();
});
}
@override
void dispose() {
_fadeTimer?.cancel();
_doneTimer?.cancel();
_controller.dispose();
_popController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final Size size = MediaQuery.sizeOf(context);
return Scaffold(
body: FadeTransition(
opacity: _opacity,
child: Container(
width: size.width,
height: size.height,
color: AppColors.background,
child: SafeArea(
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ScaleTransition(
scale: _pop,
child: const Text(
SplashStrings.greeting,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 64,
fontWeight: FontWeight.w900,
color: AppColors.pinkLight,
height: 1.0,
),
),
),
],
),
),
),
),
),
);
}
}