gpt4 book ai didi

flutter - 复选框在对话框中切换

转载 作者:行者123 更新时间:2023-12-03 03:58:49 25 4
gpt4 key购买 nike

对话框中的复选框切换不实时更新吗????
当我必须onChanged而不更新对话框中的复选框时

var is_checked = false;
void updateCheckBox() {
showGeneralDialog(
pageBuilder: (context, _, __) {
return new Row(
children: <Widget>[
new Checkbox(
value: is_checked,
onChanged: (bool value) {
this.setState((){
is_checked = !is_checked;
});
},
),
Text(
' Confirm bets before placing',
style: TextStyle(
fontFamily:"Roboto",fontSize: 14.0, fontWeight: FontWeight.normal),
)],
);
},
);
}

最佳答案

更改此:

              new Checkbox(
value: is_checked,
onChanged: (bool value) {
this.setState((){
is_checked = !is_checked;
});
},
),

到这个:
              new Checkbox(
value: is_checked,
onChanged: (bool value) {
this.setState((){
is_checked = value;
});
},
),

When the checkbox is tapped, if tristate is false (the default) then the onChanged callback will be applied to !value. If tristate is true this callback cycle from false to true to null.



检查文档:

https://api.flutter.dev/flutter/material/Checkbox/onChanged.html

关于flutter - 复选框在对话框中切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58872797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com