使用checkboxlisttile在flutter中使用CheckboxListtile时是否可以知道触发复选框或项目文本
我正在使用CheckBoxListtile在Flutter中显示一些待办事项(v3.0.4
)。这是代码看起来像:
CheckboxListTile(
controlAffinity: ListTileControlAffinity.leading,
title: Text(element.name,style:element.isCompleted == 1? TextStyle(color: Colors.grey):TextStyle(color: Colors.black)),
value: element.isCompleted == 1?true:false,
checkColor: Colors.green,
selected: element.isCompleted == 1?true:false,
onChanged: (bool? value) {
if(value!){
element.isCompleted = 1;
}else{
element.isCompleted = 0;
}
TodoProvider.updateTodo(element).then((value) => {
TodoProvider.getTodos().then((todos) => {
buildTodoItems(todos)
})
});
},
))
用户点击checkboxlisttile项目文本时,我想显示待办事项详细信息,当用户点击复选框时,我想更改待办事项任务以完成。现在,我面临的问题是,我无法检测到用户点击的哪一部分,一路触发onchange事件。我已经阅读了CheckBoxListtile源代码,似乎没有API可以执行此操作。我想念什么吗?我应该怎么做才能检测用户选择哪一部分?
I am using CheckboxListTile to show some todo item in flutter(v3.0.4
). This is the code looks like:
CheckboxListTile(
controlAffinity: ListTileControlAffinity.leading,
title: Text(element.name,style:element.isCompleted == 1? TextStyle(color: Colors.grey):TextStyle(color: Colors.black)),
value: element.isCompleted == 1?true:false,
checkColor: Colors.green,
selected: element.isCompleted == 1?true:false,
onChanged: (bool? value) {
if(value!){
element.isCompleted = 1;
}else{
element.isCompleted = 0;
}
TodoProvider.updateTodo(element).then((value) => {
TodoProvider.getTodos().then((todos) => {
buildTodoItems(todos)
})
});
},
))
when the user tap the CheckboxListTile item text, I want to show the todo detail information, when the user tap the checkbox, I want to make the todo task changed to complete. Now I am facing a problem is that I could not detect which part the user tap, all the way will trigger onchange event. I have already read the CheckboxListTile source code, seems no api to do this. Am I misssing something? what should I do to detect which part the user select?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将
标题
包装在getruestector()
中。现在,当标题被点击时, 将运行手势检测器,而不是on Changed()
。在此示例中,如果您点击文本“复选框”,则可以看到实际的复选框值未更新,但eStureDetector is 被调用,如果您查看控制台“敲击”是被打印。
这是一个完整的示例。我希望你明白:
You can wrap your
title
in aGestureDetector()
. Now when the title is tapped, only the gesture detector will be run, and not theonChanged()
.In this example, if you tap on the text "Checkbox" then you can see the actual checkbox value is not being updated but the GestureDetector is being called, and if you look at the console "tapped" is being printed.
Here is a complete example. I hope you understand: