HiCache.getInstance().get(HiConstants.theme); 获取到的结果是null
来源:12-7 系统Dark Mode变化监听与适配

夏目鲸鱼
2021-06-13
HiCache.getInstance().get(HiConstants.theme); 获取到的结果是null
这个我按照老师的代码敲的,打印出的结果是null
String theme = HiCache.getInstance().get(HiConstants.theme);
class HiConstants {
static String authTokenK = "auth-Token";
static String authTokenV = "MjAyMC0wNi0yMyAwMzoyNTowMQ==fa";
static String courseFlagK = "course-flag";
static String courseFlagV = "fa";
static const theme = "System";
}
写回答
1回答
-
默认情况下因为还没有将theme存到本地所以从本地存储获取的theme是null,可参考下课程源码的实现加个默认值的处理:
///获取主题模式 ThemeMode getThemeMode() { String? theme = HiCache.getInstance().get(HiConstants.theme); switch (theme) { case 'Dark': _themeMode = ThemeMode.dark; break; case 'System': _themeMode = ThemeMode.system; break; default: _themeMode = ThemeMode.light; break; } return _themeMode!; }
00
相似问题
为什么取反?
回答 1
使用缓存字符串方法报错
回答 2