import 'package:flutter/material.dart'; import 'package:gif_view/gif_view.dart'; import 'package:qpay/main.dart'; class SplashScreen extends StatefulWidget { const SplashScreen({super.key}); @override State createState() => _SplashScreenState(); } class _SplashScreenState extends State with TickerProviderStateMixin { late AnimationController _fadeController; late AnimationController _scaleController; late Animation _fadeAnimation; late Animation _scaleAnimation; @override void initState() { super.initState(); // Initialize animation controllers _fadeController = AnimationController( duration: const Duration(milliseconds: 1000), vsync: this, ); _scaleController = AnimationController( duration: const Duration(milliseconds: 800), vsync: this, ); // Create animations _fadeAnimation = Tween(begin: 0.0, end: 1.0).animate( CurvedAnimation(parent: _fadeController, curve: Curves.easeInOut), ); _scaleAnimation = Tween(begin: 0.8, end: 1.0).animate( CurvedAnimation(parent: _scaleController, curve: Curves.elasticOut), ); // Start animations _startAnimations(); } void _startAnimations() async { try { // Start fade in and scale animations _fadeController.forward(); _scaleController.forward(); // Wait for 3 seconds (adjust as needed) await Future.delayed(const Duration(milliseconds: 1250)); // Start fade out animation await _fadeController.reverse(); // Mark splash complete so GoRouter redirect releases navigation // to the originally intended route (e.g. /poll/:id). if (mounted) { splashState.finish(); } } catch (e) { // If there's an error, still complete the splash screen if (mounted) { splashState.finish(); } } } @override void dispose() { _fadeController.dispose(); _scaleController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, body: AnimatedBuilder( animation: Listenable.merge([_fadeController, _scaleController]), builder: (context, child) { return FadeTransition( opacity: _fadeAnimation, child: ScaleTransition( scale: _scaleAnimation, child: Center( child: SizedBox( width: 200, child: ClipRRect( borderRadius: BorderRadius.circular(20), child: GifView.asset( 'assets/velocity-animation.gif', width: MediaQuery.of(context).size.width, height: MediaQuery.of(context).size.height, frameRate: 30, fit: BoxFit.contain, ), ), ), ), ), ); }, ), ); } }