基本完成
This commit is contained in:
48
lib/data/local/storage.dart
Normal file
48
lib/data/local/storage.dart
Normal file
@@ -0,0 +1,48 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class Storage {
|
||||
//存储数据
|
||||
static Future<void> set(String key, dynamic value) async {
|
||||
SharedPreferences sp = await SharedPreferences.getInstance();
|
||||
if (value is String) {
|
||||
sp.setString(key, value);
|
||||
} else if (value is int) {
|
||||
sp.setInt(key, value);
|
||||
} else if (value is bool) {
|
||||
sp.setBool(key, value);
|
||||
} else if (value is double) {
|
||||
sp.setDouble(key, value);
|
||||
} else if (value is Map) {
|
||||
String jsonStr = jsonEncode(value);
|
||||
sp.setString(key, jsonStr);
|
||||
}
|
||||
}
|
||||
|
||||
//获取数据
|
||||
static Future<dynamic> get(String key) async {
|
||||
SharedPreferences sp = await SharedPreferences.getInstance();
|
||||
var value = sp.get(key);
|
||||
if (value is String) {
|
||||
try {
|
||||
return jsonDecode(value);
|
||||
} catch (e) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
//删除数据
|
||||
static Future<void> remove(key) async {
|
||||
SharedPreferences sp = await SharedPreferences.getInstance();
|
||||
sp.remove(key);
|
||||
}
|
||||
|
||||
//判断键是否存在
|
||||
static Future<bool> hasKey(String key) async {
|
||||
SharedPreferences sp = await SharedPreferences.getInstance();
|
||||
return sp.containsKey(key);
|
||||
}
|
||||
}
|
||||
8
lib/data/models/other_login_type.dart
Normal file
8
lib/data/models/other_login_type.dart
Normal file
@@ -0,0 +1,8 @@
|
||||
enum OtherLoginType {
|
||||
google('google'),
|
||||
apple('apple');
|
||||
|
||||
const OtherLoginType(this.value);
|
||||
|
||||
final String value;
|
||||
}
|
||||
22
lib/data/models/skin_check_status.dart
Normal file
22
lib/data/models/skin_check_status.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
enum SkinCheckStatus {
|
||||
/// 正常
|
||||
normal(1),
|
||||
|
||||
/// 警告
|
||||
warning(2),
|
||||
|
||||
/// 危险
|
||||
danger(3),
|
||||
|
||||
/// 未知
|
||||
unknown(0);
|
||||
|
||||
final int value;
|
||||
|
||||
const SkinCheckStatus(this.value);
|
||||
|
||||
/// 根据 int 值返回对应的枚举,默认返回 online
|
||||
static SkinCheckStatus fromValue(int value) {
|
||||
return SkinCheckStatus.values.firstWhere((e) => e.value == value, orElse: () => SkinCheckStatus.unknown);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user