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

100 lines
2.8 KiB
Dart

import 'package:flutter/material.dart';
import '../../core/theme.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: AppTheme.primaryDark,
body: Center(
child: FadeTransition(
opacity: _fadeAnimation,
child: ScaleTransition(
scale: _scaleAnimation,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: 100,
height: 100,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(AppTheme.radiusLg),
boxShadow: AppTheme.shadowLg,
),
child: const Icon(
Icons.diamond_outlined,
size: 60,
color: AppTheme.primaryDark,
),
),
const SizedBox(height: AppTheme.spacingLg),
Text(
"MPG HRIS",
style: AppTheme.heading1.copyWith(color: Colors.white),
),
Text(
"Sistem Informasi SDM",
style: AppTheme.bodyMedium.copyWith(color: Colors.white70),
),
],
),
),
),
),
);
}
}