| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- // 简单封装 shared preferences 避免忘记代码
- import 'package:shared_preferences/shared_preferences.dart';
- class SharedStore {
- final Future<SharedPreferences> sharedStorage = SharedPreferences.getInstance();
- //
- Future<bool?> getBool(String key) async {
- SharedPreferences prefs = await sharedStorage;
- return prefs.getBool(key);
- }
- Future<bool> setBool(String key, bool value) async {
- SharedPreferences prefs = await sharedStorage;
- return prefs.setBool(key, value);
- }
- //
- Future<double?> getDouble(String key) async {
- SharedPreferences prefs = await sharedStorage;
- return prefs.getDouble(key);
- }
- Future<bool> setDouble(String key, double value) async {
- SharedPreferences prefs = await sharedStorage;
- return prefs.setDouble(key, value);
- }
- //
- Future<int?> getInt(String key) async {
- SharedPreferences prefs = await sharedStorage;
- return prefs.getInt(key);
- }
- Future<bool> setInt(String key, int value) async {
- SharedPreferences prefs = await sharedStorage;
- return prefs.setInt(key, value);
- }
- //
- Future<String?> getString(String key) async {
- SharedPreferences prefs = await sharedStorage;
- return prefs.getString(key);
- }
- Future<bool> setString(String key, String str) async {
- SharedPreferences prefs = await sharedStorage;
- return prefs.setString(key, str);
- }
- //
- Future<List<String>?> getStringList(String key) async {
- SharedPreferences prefs = await sharedStorage;
- return prefs.getStringList(key);
- }
- Future<bool> setStringList(String key, List<String> list) async {
- SharedPreferences prefs = await sharedStorage;
- return prefs.setStringList(key, list);
- }
- }
|