|
123456789101112131415161718192021222324252627282930 |
- import 'dart:convert';
-
- import 'package:shared_preferences/shared_preferences.dart';
- import 'package:zhiying_comm/util/empty_util.dart';
-
- class SharedPreferencesUtil {
- static Future<Map<String, dynamic>> getNetCacheResult(String key) async {
- if (!EmptyUtil.isEmpty(key)) {
- SharedPreferences prefs = await SharedPreferences.getInstance();
- String cacheResult = prefs.getString(key);
- // TODO need解密?
- if (!EmptyUtil.isEmpty(cacheResult)) {
- Map<String, dynamic> map = json.decode(cacheResult);
- if(!EmptyUtil.isEmpty(map)) {
- return map;
- }
- }
- }
- return null;
- }
-
- static Future<void> setNetCacheResult(String key, String value) async {
- if (!EmptyUtil.isEmpty(key) && !EmptyUtil.isEmpty(value)) {
- SharedPreferences prefs = await SharedPreferences.getInstance();
- // TODO need加密?
- prefs.setString(key, value);
- }
- return;
- }
- }
|