-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshared_preferences_helper.dart
54 lines (43 loc) · 1.67 KB
/
shared_preferences_helper.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import 'package:shared_preferences/shared_preferences.dart';
class SharedPreferencesHelper {
SharedPreferencesHelper._();
static Future<void> setString(String key, String value) async {
final SharedPreferences instance = await SharedPreferences.getInstance();
await instance.setString(key, value);
return;
}
static Future<void> removeString(String key) async {
final SharedPreferences instance = await SharedPreferences.getInstance();
instance.remove(key);
}
static Future<String?> getString(String key) async {
final SharedPreferences instance = await SharedPreferences.getInstance();
return instance.getString(key);
}
static Future<void> setBoolean(String key, bool value) async {
final SharedPreferences instance = await SharedPreferences.getInstance();
instance.setBool(key, value);
}
static Future<bool?> getBoolean(String key) async {
final SharedPreferences instance = await SharedPreferences.getInstance();
return instance.getBool(key);
}
static Future<void> setInt(String key, int value) async {
final SharedPreferences instance = await SharedPreferences.getInstance();
instance.setInt(key, value);
}
static Future<int?> getInt(String key) async {
final SharedPreferences instance = await SharedPreferences.getInstance();
return instance.getInt(key);
}
static Future<void> clearAllData() async {
final SharedPreferences instance = await SharedPreferences.getInstance();
instance.clear();
}
static Future<void> clearSessionData() async {
final SharedPreferences instance = await SharedPreferences.getInstance();
// instance.clear();
//instance.remove(savedToken);
//..
}
}