97 lines
3.0 KiB
Dart
97 lines
3.0 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:Tripz/views/auth/login_page.dart';
|
|
import 'package:package_info_plus/package_info_plus.dart';
|
|
// import 'package:uni_links/uni_links.dart';
|
|
|
|
import '../../constant/box_name.dart';
|
|
import '../../main.dart';
|
|
import '../../onbording_page.dart';
|
|
import '../auth/login_controller.dart';
|
|
|
|
class SplashScreenController extends GetxController
|
|
with GetTickerProviderStateMixin {
|
|
late AnimationController _animationController;
|
|
late Animation<double> animation;
|
|
final progress = 0.0.obs;
|
|
Timer? _progressTimer;
|
|
|
|
String packageInfo = '';
|
|
|
|
Future<void> _getPackageInfo() async {
|
|
final info = await PackageInfo.fromPlatform();
|
|
packageInfo = info.version;
|
|
box.write(BoxName.packagInfo, packageInfo);
|
|
update();
|
|
}
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
_getPackageInfo();
|
|
_animationController = AnimationController(
|
|
vsync: this,
|
|
duration: const Duration(milliseconds: 1500), // Reduced duration
|
|
)..forward();
|
|
|
|
animation =
|
|
CurvedAnimation(parent: _animationController, curve: Curves.easeOut);
|
|
|
|
startTimer();
|
|
_startProgressTimer();
|
|
}
|
|
|
|
void _startProgressTimer() {
|
|
const totalTime = 3000; // 5 seconds in milliseconds
|
|
const interval = 50; // Update every 50ms
|
|
int elapsed = 0;
|
|
|
|
_progressTimer =
|
|
Timer.periodic(const Duration(milliseconds: interval), (timer) async {
|
|
elapsed += interval;
|
|
progress.value = (elapsed / totalTime).clamp(0.0, 1.0);
|
|
|
|
if (elapsed >= totalTime) {
|
|
timer.cancel();
|
|
box.read(BoxName.onBoarding) == null
|
|
? Get.off(() => OnBoardingPage())
|
|
: box.read(BoxName.email) != null &&
|
|
box.read(BoxName.phone) != null &&
|
|
box.read(BoxName.isVerified) == '1'
|
|
// ? Get.off(() => const MapPagePassenger())
|
|
? await Get.put(LoginController()).loginUsingCredentials(
|
|
box.read(BoxName.passengerID).toString(),
|
|
box.read(BoxName.email).toString(),
|
|
)
|
|
: Get.off(() => LoginPage());
|
|
}
|
|
});
|
|
}
|
|
|
|
void startTimer() async {
|
|
Timer(const Duration(seconds: 5), () async {
|
|
// box.read(BoxName.onBoarding) == null
|
|
// ? Get.off(() => OnBoardingPage())
|
|
// : box.read(BoxName.email) != null &&
|
|
// box.read(BoxName.phone) != null &&
|
|
// box.read(BoxName.isVerified) == '1'
|
|
// // ? Get.off(() => const MapPagePassenger())
|
|
// ? await Get.put(LoginController()).loginUsingCredentials(
|
|
// box.read(BoxName.passengerID).toString(),
|
|
// box.read(BoxName.email).toString(),
|
|
// )
|
|
// : Get.off(() => LoginPage());
|
|
});
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
_progressTimer?.cancel();
|
|
_animationController.dispose();
|
|
super.onClose();
|
|
}
|
|
}
|