MIF_E31230910_MP-HRIS-MOBILE/lib/screens/splash_screen.dart

83 lines
2.1 KiB
Dart

import 'package:flutter/material.dart';
import '../../core/cache_manager.dart';
class SplashScreen extends StatefulWidget {
const SplashScreen({super.key});
@override
State<SplashScreen> createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> with SingleTickerProviderStateMixin {
late AnimationController _controller;
late Animation<double> _fadeAnimation;
late Animation<double> _scaleAnimation;
@override
void initState() {
super.initState();
_controller = AnimationController(
vsync: this,
duration: const Duration(seconds: 2),
);
_fadeAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(
CurvedAnimation(parent: _controller, curve: Curves.easeIn),
);
_scaleAnimation = Tween<double>(begin: 0.8, end: 1.0).animate(
CurvedAnimation(parent: _controller, curve: Curves.easeOutBack),
);
_controller.forward();
Future.delayed(const Duration(seconds: 3), () {
_checkAuthAndNavigate();
});
}
void _checkAuthAndNavigate() {
if (!mounted) return;
final token = CacheManager.authBox.get('auth_token');
if (token != null && token.toString().isNotEmpty) {
Navigator.pushReplacementNamed(context, '/onboarding/check');
} else {
Navigator.pushReplacementNamed(context, '/login');
}
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Center(
child: FadeTransition(
opacity: _fadeAnimation,
child: ScaleTransition(
scale: _scaleAnimation,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
'assets/images/logo.png',
height: 120, // slightly larger since it's not in a box
width: 250,
fit: BoxFit.contain,
),
],
),
),
),
),
);
}
}