97 lines
2.8 KiB
Dart
97 lines
2.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:get_storage/get_storage.dart';
|
|
import 'package:logger/logger.dart';
|
|
import 'package:lottie/lottie.dart';
|
|
import 'package:sigap/src/features/auth/data/repositories/authentication_repository.dart';
|
|
import 'package:sigap/src/utils/constants/app_routes.dart';
|
|
import 'package:sigap/src/utils/constants/colors.dart';
|
|
import 'package:sigap/src/utils/constants/image_strings.dart';
|
|
import 'package:sigap/src/utils/helpers/helper_functions.dart';
|
|
|
|
class AnimatedSplashScreenWidget extends StatefulWidget {
|
|
const AnimatedSplashScreenWidget({super.key});
|
|
|
|
@override
|
|
State<AnimatedSplashScreenWidget> createState() =>
|
|
_AnimatedSplashScreenWidgetState();
|
|
}
|
|
|
|
class _AnimatedSplashScreenWidgetState extends State<AnimatedSplashScreenWidget>
|
|
with SingleTickerProviderStateMixin {
|
|
late AnimationController _animationController;
|
|
late Animation<double> _animation;
|
|
final storage = GetStorage();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
_animationController = AnimationController(
|
|
duration: const Duration(milliseconds: 1500),
|
|
vsync: this,
|
|
);
|
|
|
|
_animation = CurvedAnimation(
|
|
parent: _animationController,
|
|
curve: Curves.easeInOut,
|
|
);
|
|
|
|
_animationController.forward();
|
|
|
|
// Delay for splash screen duration
|
|
Future.delayed(const Duration(milliseconds: 3500), () {
|
|
_handleNavigation();
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_animationController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
Future<void> _handleNavigation() async {
|
|
try {
|
|
// Check if AuthenticationRepository is registered
|
|
if (Get.isRegistered<AuthenticationRepository>()) {
|
|
AuthenticationRepository.instance.screenRedirect();
|
|
} else {
|
|
Logger().e(
|
|
'AuthenticationRepository not registered, manually registering',
|
|
);
|
|
final authRepo = Get.put(AuthenticationRepository(), permanent: true);
|
|
authRepo.screenRedirect();
|
|
}
|
|
} catch (e) {
|
|
Logger().e('Error during navigation: $e');
|
|
// Fallback to onboarding screen if there's an error
|
|
Get.offAllNamed(AppRoutes.onboarding);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final isDark = THelperFunctions.isDarkMode(context);
|
|
final isFirstTime = storage.read('isFirstTime') ?? false;
|
|
|
|
Logger().i('isFirstTime: $isFirstTime');
|
|
|
|
return Scaffold(
|
|
backgroundColor: isDark ? TColors.dark : TColors.white,
|
|
body: Center(
|
|
child: FadeTransition(
|
|
opacity: _animation,
|
|
child: Lottie.asset(
|
|
isDark ? TImages.darkSplashApp : TImages.lightSplashApp,
|
|
frameRate: FrameRate.max,
|
|
repeat: true,
|
|
width: 300,
|
|
height: 300,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|