120 lines
3.6 KiB
Dart
120 lines
3.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:ftc_mobile_app/utilities/app_session_manager.dart';
|
|
import 'package:ftc_mobile_app/utilities/extensions/custom_extensions.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:ftc_mobile_app/ftc_mobile_app.dart';
|
|
|
|
class SplashScreenController extends GetxController {
|
|
final GlobalKey<ScaffoldState> screenKey = GlobalKey<ScaffoldState>();
|
|
|
|
@override
|
|
void onInit() {
|
|
5.seconds.delay(() {
|
|
_gotoLoginScreen();
|
|
|
|
// if (_loginTokenNotFound) {
|
|
// _gotoLoginScreen();
|
|
// } else {
|
|
// _checkOngoingShift();
|
|
// }
|
|
|
|
});
|
|
super.onInit();
|
|
}
|
|
|
|
//true if login token found in local storage
|
|
bool get _loginTokenNotFound {
|
|
return LocalStorageManager.getLoginToken().isEmpty;
|
|
}
|
|
|
|
DateTime _getDateTimeObjFor({required int hour, required int minute}) {
|
|
return DateTime(DateTime.now().year, DateTime.now().month,
|
|
DateTime.now().day, hour, minute);
|
|
}
|
|
|
|
//Todo: If Shift present then logout half an hour before start time
|
|
// Else logout 7am uk time
|
|
_checkOngoingShift() {
|
|
final shift = LocalStorageManager.getOngoingShift();
|
|
|
|
//if shift present
|
|
if (shift != null) {
|
|
///boolean value [isShiftExpired] to check
|
|
///if there is an expired shift in local storage.
|
|
final isShiftExpired = shift.endTime!.isBefore(TimeOfDay.now());
|
|
if (isShiftExpired) {
|
|
LocalStorageManager.removeOngoingShift();
|
|
} else {
|
|
final shiftNotStartedYet = shift.startTime!.isAfter(TimeOfDay.now());
|
|
|
|
if (shiftNotStartedYet) {
|
|
///checking if shift is going to start in 30 minutes or less
|
|
if ((shift.startTime!.minute - TimeOfDay.now().minute) <= 30) {
|
|
_gotoLoginScreen();
|
|
return;
|
|
}
|
|
|
|
///checking if shift is going to start in 60 minutes or less, then
|
|
///start session timer which will alert session expire to user
|
|
///if 30minutes left in shift start and logout the user.
|
|
if ((shift.startTime!.minute - TimeOfDay.now().minute) <= 60) {
|
|
//starting session timer
|
|
|
|
final sessionExpireDateTime = _getDateTimeObjFor(
|
|
hour: shift.startTime!.hour,
|
|
minute: shift.startTime!.minute,
|
|
).subtract(30.minutes);
|
|
|
|
final millisLeft = sessionExpireDateTime.millisecondsSinceEpoch -
|
|
DateTime.now().millisecondsSinceEpoch;
|
|
|
|
AppSessionManager.instance.startSessionTimer(millisLeft);
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
final currentTime = TimeOfDay.now();
|
|
const time7am = TimeOfDay(hour: 7, minute: 0);
|
|
|
|
///checking if current time is before [7:00 AM]
|
|
if (currentTime.isBefore(time7am)) {
|
|
///checking if remaining 30 minutes or less time
|
|
if ((time7am.minute - currentTime.minute) <= 30) {
|
|
//starting session timer
|
|
final dateTime7am =
|
|
_getDateTimeObjFor(hour: time7am.hour, minute: time7am.minute);
|
|
|
|
final millisLeft = dateTime7am.millisecondsSinceEpoch -
|
|
DateTime.now().millisecondsSinceEpoch;
|
|
|
|
AppSessionManager.instance.startSessionTimer(millisLeft);
|
|
}
|
|
}
|
|
}
|
|
|
|
_gotoDashboardScreen();
|
|
}
|
|
|
|
_gotoLoginScreen() {
|
|
Navigator.pushNamedAndRemoveUntil(
|
|
screenKey.currentContext!,
|
|
CustomRouteNames.kLoginScreenRoute,
|
|
(route) => false,
|
|
);
|
|
}
|
|
|
|
_gotoDashboardScreen() {
|
|
Navigator.pushNamedAndRemoveUntil(
|
|
screenKey.currentContext!,
|
|
CustomRouteNames.kDashboardScreenRoute,
|
|
(route) => false,
|
|
);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
Get.delete<SplashScreenController>();
|
|
super.dispose();
|
|
}
|
|
}
|