···11import 'dart:async';
22import 'package:flutter/cupertino.dart';
33+import 'package:provider/provider.dart';
44+import '../services/auth_service.dart';
35import '../utils/app_colors.dart';
4657class SplashScreen extends StatefulWidget {
···30323133 _animationController.forward();
32343333- // Simply go to the main screen after a delay
3434- Timer(const Duration(seconds: 3), () {
3535- if (mounted) {
3636- Navigator.of(context).pushReplacementNamed('/home');
3737- }
3838- });
3535+ // Check if user is already authenticated
3636+ _checkAuthentication();
3737+ }
3838+3939+ Future<void> _checkAuthentication() async {
4040+ // Wait for animations to complete
4141+ await Future.delayed(const Duration(seconds: 2));
4242+4343+ if (!mounted) return;
4444+4545+ final authService = Provider.of<AuthService>(context, listen: false);
4646+4747+ // Wait for auth service to finish loading saved session
4848+ while (authService.isLoading) {
4949+ await Future.delayed(const Duration(milliseconds: 100));
5050+ if (!mounted) return;
5151+ }
5252+5353+ // Check if session is valid
5454+ final bool isSessionValid = await authService.validateSession();
5555+5656+ if (!mounted) return;
5757+5858+ if (isSessionValid) {
5959+ // User is authenticated, go to home
6060+ Navigator.of(context).pushReplacementNamed('/home');
6161+ } else {
6262+ // User is not authenticated, go to login
6363+ Navigator.of(context).pushReplacementNamed('/auth');
6464+ }
3965 }
40664167 @override