mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 09:45:22 +00:00
91 lines
2.9 KiB
Dart
91 lines
2.9 KiB
Dart
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
class SharedPreferencesHelper {
|
|
// isRegistered flag to know if the user has entered his fullname and email or not (is he registered or not)
|
|
static bool? isRegistered;
|
|
|
|
// flags to detect the mode {regular, onboarding, demo}
|
|
static bool? isDemo;
|
|
static bool? isOnBoarding;
|
|
|
|
// isDemoAndUseToken flag to use the user token in the header of the request in the demo experience, instead of "Demo" header in situations (1. openning the profile request 2. updating th user data -registeration- request)
|
|
static bool? isDemoAndUseToken;
|
|
|
|
// addedFirstProperty flag to detect if the user has added his first property or not
|
|
static bool? addedFirstProperty;
|
|
|
|
// stores the user id value
|
|
static String? userIdValue;
|
|
|
|
// stores the phone number value
|
|
static String? phoneNumber;
|
|
|
|
//stores the country code of the user phone
|
|
static String? countryCode;
|
|
|
|
// static Future<bool?> getIsDemoValue() async {
|
|
// isDemo = await readBoolFromSP(KeyConstants.isDemoFlag) ?? false;
|
|
// return isDemo;
|
|
// }
|
|
//
|
|
// static Future<bool?> getIsOnboardingValue() async {
|
|
// isOnBoarding = await readBoolFromSP(KeyConstants.isOnboardingFlag);
|
|
// return isOnBoarding;
|
|
// }
|
|
|
|
static saveStringToSP(String key, String value) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.setString(key, value);
|
|
}
|
|
|
|
static saveBoolToSP(String key, bool value) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.setBool(key, value);
|
|
}
|
|
|
|
static saveIntToSP(String key, int value) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.setInt(key, value);
|
|
}
|
|
|
|
static saveDoubleToSP(String key, double value) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.setDouble(key, value);
|
|
}
|
|
|
|
static saveStringListToSP(String key, List<String> value) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.setStringList(key, value);
|
|
}
|
|
|
|
static Future<String> readStringFromSP(String key) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
String value = prefs.getString(key) ?? '';
|
|
return value;
|
|
}
|
|
|
|
static Future<bool?> readBoolFromSP(String key) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
bool? value = prefs.getBool(key);
|
|
return value;
|
|
}
|
|
|
|
static Future<int> readIntFromSP(String key) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
int value = prefs.getInt(key) ?? 0;
|
|
return value;
|
|
}
|
|
|
|
static Future<List<String>> readStringListFromSP(String key) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
List<String>? value = prefs.getStringList(key) ?? [];
|
|
return value;
|
|
}
|
|
|
|
static Future<bool> removeValueFromSP(String key) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.remove(key);
|
|
return true;
|
|
}
|
|
}
|