fist commit ftc staff app clone
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
export 'local_storage_keys.dart';
|
||||
export 'local_storage_manager.dart';
|
||||
13
lib/utilities/local_storage_manager/local_storage_keys.dart
Normal file
13
lib/utilities/local_storage_manager/local_storage_keys.dart
Normal file
@@ -0,0 +1,13 @@
|
||||
class LocalStorageKeys {
|
||||
LocalStorageKeys._();
|
||||
|
||||
static const String kUserTokenKey = "UserTokenKey";
|
||||
static const String kUserIdKey = "UserIdKey";
|
||||
// static const String kRememberMeKey = "RememberMeKey";
|
||||
static const String kSaveEmailKey = "SaveEmailKey";
|
||||
// static const String kUserModelKey = "UserModelKey";
|
||||
// static const String kProfileModelKey = "ProfileModelKey";
|
||||
// static const String kIsUserLoggedInKey = "IsUserLoggedInKey ";
|
||||
|
||||
static const String kCurrentOngoingShift = "CurrentOngoingShift ";
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:ftc_mobile_app/models/rota/WeekArrayData.dart';
|
||||
import 'package:get_storage/get_storage.dart';
|
||||
|
||||
import 'local_storage_keys.dart';
|
||||
|
||||
abstract class LocalStorageManager {
|
||||
// LocalStorageManager._();
|
||||
//
|
||||
// static final LocalStorageManager _instance = LocalStorageManager._();
|
||||
//
|
||||
// factory LocalStorageManager() {
|
||||
// return _instance;
|
||||
// }
|
||||
|
||||
static final GetStorage _box = GetStorage();
|
||||
|
||||
static Future init() => GetStorage.init();
|
||||
|
||||
static Future<void> saveSession({
|
||||
required String tokenKey,
|
||||
required String tokenValue,
|
||||
}) async {
|
||||
await _box.write(tokenKey, tokenValue);
|
||||
}
|
||||
|
||||
static Future<void> removeSession({required String token}) async {
|
||||
await _box.remove(token);
|
||||
}
|
||||
|
||||
static String getSessionToken({required String tokenKey}) {
|
||||
return _box.read(tokenKey) ?? '';
|
||||
}
|
||||
|
||||
static Future setLoginToken(String token) async {
|
||||
await _box.write(LocalStorageKeys.kUserTokenKey, token);
|
||||
}
|
||||
|
||||
static String getLoginToken() {
|
||||
return _box.read(LocalStorageKeys.kUserTokenKey) ?? '';
|
||||
}
|
||||
|
||||
static Future setUserId(String id) async {
|
||||
await _box.write(LocalStorageKeys.kUserIdKey, id);
|
||||
}
|
||||
|
||||
static String get userId {
|
||||
return _box.read(LocalStorageKeys.kUserIdKey) ?? '';
|
||||
}
|
||||
|
||||
static void saveShiftData({required DaysArrayData data}) {
|
||||
_box.write(LocalStorageKeys.kCurrentOngoingShift, data.toJson());
|
||||
}
|
||||
|
||||
static DaysArrayData? getOngoingShift() {
|
||||
try {
|
||||
return DaysArrayData.fromJson(
|
||||
_box.read(LocalStorageKeys.kCurrentOngoingShift));
|
||||
} catch (e) {
|
||||
debugPrint(
|
||||
"LocalStorageManager.getCurrentShiftData err: ${e.toString()}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> removeOngoingShift() async {
|
||||
await _box.remove(LocalStorageKeys.kCurrentOngoingShift);
|
||||
}
|
||||
|
||||
static Future clear() {
|
||||
return _box.erase();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user