基础库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

31 lines
935 B

  1. import 'dart:convert';
  2. import 'package:shared_preferences/shared_preferences.dart';
  3. import 'package:zhiying_comm/util/empty_util.dart';
  4. class SharedPreferencesUtil {
  5. static Future<Map<String, dynamic>> getNetCacheResult(String key) async {
  6. if (!EmptyUtil.isEmpty(key)) {
  7. SharedPreferences prefs = await SharedPreferences.getInstance();
  8. String cacheResult = prefs.getString(key);
  9. // TODO need解密?
  10. if (!EmptyUtil.isEmpty(cacheResult)) {
  11. Map<String, dynamic> map = json.decode(cacheResult);
  12. if(!EmptyUtil.isEmpty(map)) {
  13. return map;
  14. }
  15. }
  16. }
  17. return null;
  18. }
  19. static Future<void> setNetCacheResult(String key, String value) async {
  20. if (!EmptyUtil.isEmpty(key) && !EmptyUtil.isEmpty(value)) {
  21. SharedPreferences prefs = await SharedPreferences.getInstance();
  22. // TODO need加密?
  23. prefs.setString(key, value);
  24. }
  25. return;
  26. }
  27. }