【发布时间】:2019-11-14 07:50:58
【问题描述】:
试图让这个开关仍然起作用,以及保存和保持应用关闭/重新打开。这些事情都没有实现,一旦激活开关,尝试将开关改回时会抛出错误。
The following assertion was thrown while handling a gesture:
type 'Future<dynamic>' is not a subtype of type 'bool'
-
void onChange(bool value) {
setState(() {
brain.units = value;
});
}
//Shared Prefs saver
void initState() {
super.initState();
_loadValue();
}
_loadValue() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
setState(() {
units = (prefs.getBool('boolValue'));
});
}
_setValue() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
setState(() {
units = (prefs.getBool('boolValue'));
prefs.setBool('boolValue', units);
});
}
Widget build(BuildContext context) {
return Container(
child: Center(
child: SwitchListTile(
title: Text(this.unitName = brain.unitClass(),
value: brain.units,
secondary: Icon(FontAwesomeIcons.balanceScale, color: kIconColor),
onChanged: (
bool value,
) {
onChange(value && _setValue());
},
),
),
);
}
}
【问题讨论】:
-
不确定发生了什么,尝试了给出的解决方案。他们暂时工作然后停止工作,现在开关根本不起作用。从版本控制恢复到旧版本,并且只有一个页面可以使用最初预期的值更改。
标签: flutter dart sharedpreferences