71 lines
2.1 KiB
Dart
71 lines
2.1 KiB
Dart
|
import 'package:shared_preferences/shared_preferences.dart';
|
||
|
|
||
|
class CustomSharedPreferences {
|
||
|
static const String key1 = 'value1';
|
||
|
static const String key2 = 'value2';
|
||
|
static const String key3 = 'value3';
|
||
|
static const String key4 = 'value4';
|
||
|
static const String key5 = 'value5';
|
||
|
|
||
|
// Method to save a string value to shared preferences
|
||
|
static Future<void> setCustomValue(String value) async {
|
||
|
final prefs = await SharedPreferences.getInstance();
|
||
|
prefs.setString(key1, value);
|
||
|
}
|
||
|
|
||
|
static Future<void> setname(String value) async {
|
||
|
final prefs = await SharedPreferences.getInstance();
|
||
|
prefs.setString(key2, value);
|
||
|
}
|
||
|
|
||
|
static Future<void> setuserid(String value) async {
|
||
|
final prefs = await SharedPreferences.getInstance();
|
||
|
prefs.setString(key3, value);
|
||
|
}
|
||
|
|
||
|
static Future<void> setusername(String value) async {
|
||
|
final prefs = await SharedPreferences.getInstance();
|
||
|
prefs.setString(key4, value);
|
||
|
}
|
||
|
|
||
|
static Future<void> setsynctime(String value) async {
|
||
|
final prefs = await SharedPreferences.getInstance();
|
||
|
prefs.setString(key5, value);
|
||
|
}
|
||
|
|
||
|
// Method to retrieve a string value from shared preferences
|
||
|
static Future<String?> getCustomValue() async {
|
||
|
final prefs = await SharedPreferences.getInstance();
|
||
|
return prefs.getString(key1);
|
||
|
}
|
||
|
|
||
|
static Future<String?> getname() async {
|
||
|
final prefs = await SharedPreferences.getInstance();
|
||
|
return prefs.getString(key2);
|
||
|
}
|
||
|
|
||
|
static Future<String?> getuserid() async {
|
||
|
final prefs = await SharedPreferences.getInstance();
|
||
|
return prefs.getString(key3);
|
||
|
}
|
||
|
|
||
|
static Future<String?> getusername() async {
|
||
|
final prefs = await SharedPreferences.getInstance();
|
||
|
return prefs.getString(key4);
|
||
|
}
|
||
|
|
||
|
static Future<String?> getsynctime() async {
|
||
|
final prefs = await SharedPreferences.getInstance();
|
||
|
return prefs.getString(key5);
|
||
|
}
|
||
|
|
||
|
static Future<void> clearAllValues() async {
|
||
|
final prefs = await SharedPreferences.getInstance();
|
||
|
await prefs.remove(key1);
|
||
|
await prefs.remove(key2);
|
||
|
await prefs.remove(key3);
|
||
|
await prefs.remove(key4);
|
||
|
await prefs.remove(key5);
|
||
|
}
|
||
|
}
|