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