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

95 lines
2.5 KiB
Dart

import 'package:flutter/material.dart';
import '../../core/cache_manager.dart';
class SplashScreen extends StatefulWidget {
final bool launchedFromNotification;
const SplashScreen({super.key, this.launchedFromNotification = false});
@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');
// MB-07: Jika app dibuka dari push notification (terminated state),
// langsung arahkan ke halaman notifikasi setelah onboarding selesai.
if (widget.launchedFromNotification) {
Future.delayed(const Duration(milliseconds: 800), () {
if (mounted) {
Navigator.pushNamed(context, '/notification');
}
});
}
} 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,
width: 250,
fit: BoxFit.contain,
),
],
),
),
),
),
);
}
}