Files
FlutterUnit/lib/storage/dao/local_storage.dart
2020-06-19 09:59:57 +08:00

32 lines
743 B
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:shared_preferences/shared_preferences.dart';
/// create by 张风捷特烈 on 2020/6/17
/// contact me by email 1981462002@qq.com
/// 说明:
class LocalStorage {
static String tokenKey= "token_key";
static SharedPreferences _sp;
// 如果_sp已存在直接返回为null时创建
static Future<SharedPreferences> get sp async {
if (_sp == null) {
_sp = await SharedPreferences.getInstance();
}
return _sp;
}
static Future<bool> save(String key, String value) async {
return (await sp).setString(key, value);
}
static dynamic get(String key) async {
return (await sp).get(key);
}
static Future<bool> remove(String key) async {
return (await sp).remove(key);
}
}