123456789101112131415161718 |
- import 'package:shared_preferences/shared_preferences.dart';
- class LocalShare {
- static Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
- static Future<void> saveData(String key, String value) async {
- SharedPreferences prefs = await _prefs;
- prefs.setString(key, value);
- // 其他数据类型可以使用prefs.setInt, prefs.setBool等
- }
- static Future<String> readData(String key) async {
- SharedPreferences prefs = await _prefs;
- String data = prefs.getString(key) ?? '';
- return data;
- }
- }
|