import 'dart:async'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import '../providers/auth_provider.dart'; import 'main_bottom_nav.dart'; import 'welcome_screen.dart'; class SplashScreen extends StatefulWidget { const SplashScreen({super.key}); @override State createState() => _SplashScreenState(); } class _SplashScreenState extends State with TickerProviderStateMixin { late AnimationController _mainController; late Animation _scaleAnim; late Animation _fadeAnim; late AnimationController _floatController; late Animation _floatAnim; @override void initState() { super.initState(); // MAIN splash animation _mainController = AnimationController( vsync: this, duration: const Duration(milliseconds: 1200), ); _scaleAnim = Tween(begin: 0.6, end: 1.0).animate( CurvedAnimation(parent: _mainController, curve: Curves.easeOutBack), ); _fadeAnim = Tween(begin: 0.0, end: 1.0).animate( CurvedAnimation(parent: _mainController, curve: Curves.easeIn), ); // FLOATING animation (infinite) _floatController = AnimationController( vsync: this, duration: const Duration(seconds: 2), )..repeat(reverse: true); _floatAnim = Tween(begin: -10, end: 10).animate( CurvedAnimation(parent: _floatController, curve: Curves.easeInOut), ); _mainController.forward(); _init(); } Future _init() async { await Future.delayed(const Duration(milliseconds: 700)); final auth = Provider.of(context, listen: false); await auth.init(); if (!mounted) return; Future.delayed(const Duration(milliseconds: 900), () { Navigator.pushReplacement( context, MaterialPageRoute( builder: (_) => auth.isLoggedIn ? const MainBottomNav() : const WelcomeScreen(), ), ); }); } @override void dispose() { _mainController.dispose(); _floatController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { final width = MediaQuery.of(context).size.width; // Responsive scale factor final scale = (width / 430).clamp(0.9, 1.3); return Scaffold( body: Container( decoration: BoxDecoration( gradient: LinearGradient( colors: [ Colors.blue.shade50, Colors.white, ], begin: Alignment.topCenter, end: Alignment.bottomCenter, ), ), width: double.infinity, height: double.infinity, child: Center( child: AnimatedBuilder( animation: _mainController, builder: (_, __) { return Opacity( opacity: _fadeAnim.value, child: Transform.translate( offset: Offset(0, _floatAnim.value), // ⭐ Floating animation child: Column( mainAxisSize: MainAxisSize.min, children: [ // ⭐ Animated Floating White Circle Logo Transform.scale( scale: _scaleAnim.value, child: AnimatedBuilder( animation: _floatController, builder: (_, __) { return Container( width: width * 0.50 * scale, height: width * 0.50 * scale, decoration: BoxDecoration( shape: BoxShape.circle, color: Colors.white, boxShadow: [ BoxShadow( color: Colors.black .withOpacity(0.08 + (_floatAnim.value.abs() / 200)), blurRadius: 25 * scale, spreadRadius: 4 * scale, offset: Offset(0, 8 * scale), ), ], ), child: Padding( padding: EdgeInsets.all(28 * scale), child: Image.asset( "assets/Images/K.png", fit: BoxFit.contain, ), ), ); }, ), ), SizedBox(height: 22 * scale), Text( "Kent Logistics", style: TextStyle( fontSize: 22 * scale, fontWeight: FontWeight.w700, letterSpacing: 1.1, ), ), SizedBox(height: 6 * scale), Text( "Delivering Excellence", style: TextStyle( fontSize: 14 * scale, color: Colors.black54, ), ) ], ), ), ); }, ), ), ), ); } }