Share.dart 540 B

123456789101112131415161718
  1. import 'package:shared_preferences/shared_preferences.dart';
  2. class LocalShare {
  3. static Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
  4. static Future<void> saveData(String key, String value) async {
  5. SharedPreferences prefs = await _prefs;
  6. prefs.setString(key, value);
  7. // 其他数据类型可以使用prefs.setInt, prefs.setBool等
  8. }
  9. static Future<String> readData(String key) async {
  10. SharedPreferences prefs = await _prefs;
  11. String data = prefs.getString(key) ?? '';
  12. return data;
  13. }
  14. }