flutter - Flutter:CheckboxTile刻度线不变
问题描述
我正在尝试在 Flutter 中使用 Checkboxtile。但是,点击它并不会改变刻度的状态。这是代码。
bool checkedValue = false;
CheckboxListTile(
title: Text("title text"),
value: checkedValue,
onChanged: (newValue) {
setState(() {
checkedValue = newValue;
});
},
//onChanged: (newValue) { ... },
controlAffinity: ListTileControlAffinity.leading, // <-- leading Checkbox
),
你能帮我找到问题吗。为什么它不起作用。
解决方案
这可能对你有用。
class CheckBoxCustom extends StatefulWidget {
@override
_CheckBoxCustomState createState() => _CheckBoxCustomState();
}
class _CheckBoxCustomState extends State<CheckBoxCustom> {
bool checkedValue = false;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: CheckboxListTile(
title: Text("title text"),
value: checkedValue,
onChanged: (newValue) {
setState(() {
checkedValue = newValue;
});
},
controlAffinity:
ListTileControlAffinity.leading, // <-- leading Checkbox
),
),
);
}
}
推荐阅读
- mysql - MySQL 不允许我在 UPDATE 和 SET 命令之后添加 FROM 命令
- python - 当我尝试更新它时,PIP 说它是最新的,但它不是
- postgresql - 有没有办法找到每一行的总和?PostgreSQL
- java - Java8:G1GC Remark 阶段的类卸载耗时太长
- amazon-web-services - HTTP ERROR 408 - 设置 kubernetes 以及 AWS ELB 和 NGINX Ingress 之后
- python - 如何在python中解开子进程解析xml
- python - 如果我将所有内容都正确放入,我该怎么做才能修复此语法错误?
- reactjs - React Native Maps - 标记重绘功能仍然有效?
- javascript - GET http://0.0.0.0:8080/index.html?age=8&rel= 404 (/找不到对象)
- ios - 我的符号化崩溃报告看起来不像符号化的