import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; import '../../config/app_config.dart'; import '../auth/auth_provider.dart'; class SplashScreen extends ConsumerStatefulWidget { const SplashScreen({super.key}); @override ConsumerState createState() => _SplashScreenState(); } class _SplashScreenState extends ConsumerState with SingleTickerProviderStateMixin { late AnimationController _controller; late Animation _fadeAnimation; @override void initState() { super.initState(); _controller = AnimationController( vsync: this, duration: const Duration(seconds: 2), ); _fadeAnimation = Tween(begin: 0.0, end: 1.0).animate(_controller); _controller.forward().then((_) { _checkAuthAndNavigate(); }); } Future _checkAuthAndNavigate() async { // Wait an additional second for effect await Future.delayed(const Duration(seconds: 1)); if (!mounted) return; final isLoggedIn = await ref.read(authProvider.notifier).checkLoginState(); if (isLoggedIn) { context.go('/camera'); } else { context.go('/login'); } } @override void dispose() { _controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, // Changed to white to seamlessly blend with the logo body: Center( child: FadeTransition( opacity: _fadeAnimation, child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Image.asset( 'assets/logo.png', width: 150, height: 150, errorBuilder: (context, error, stackTrace) => const Icon( Icons.storefront, size: 100, color: AppConfig.primaryColor // Changed fallback icon color ), ), const SizedBox(height: AppConfig.spaceXL), Text( AppConfig.appName, style: AppConfig.h1.copyWith(color: AppConfig.primaryColor), // Red text ), const SizedBox(height: AppConfig.spaceSmall), Text( 'PT. Primafood International', style: AppConfig.bodyMedium.copyWith(color: AppConfig.textSecondary), // Grey text ), ], ), ), ), ); } }