43 lines
1.0 KiB
Dart
43 lines
1.0 KiB
Dart
import 'package:ftc_mobile_app/dialogs/app_dialogs.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:stop_watch_timer/stop_watch_timer.dart';
|
|
|
|
class AppSessionManager extends GetxService {
|
|
static AppSessionManager instance = Get.find<AppSessionManager>();
|
|
|
|
StopWatchTimer? _stopWatchTimer;
|
|
|
|
startSessionTimer(int millis) async {
|
|
await _stopAndInitTimer(millis);
|
|
_stopWatchTimer?.onStartTimer();
|
|
}
|
|
|
|
_stopTimer() async {
|
|
_stopWatchTimer?.onStopTimer();
|
|
await _stopWatchTimer?.dispose();
|
|
_stopWatchTimer = null;
|
|
}
|
|
|
|
_stopAndInitTimer(int millis) async {
|
|
_stopTimer();
|
|
_initTimer(millis);
|
|
}
|
|
|
|
_initTimer(int millis) {
|
|
_stopWatchTimer = StopWatchTimer(
|
|
mode: StopWatchMode.countDown,
|
|
presetMillisecond: millis,
|
|
onEnded: () {
|
|
_stopTimer();
|
|
//Todo: Show session expire dialog and logout from app
|
|
|
|
if (Get.isOverlaysOpen) Get.back();
|
|
AppDialog.showUnauthorizedAlert();
|
|
});
|
|
}
|
|
|
|
dispose() {
|
|
_stopWatchTimer?.dispose();
|
|
}
|
|
}
|