[英]I am getting this error in my Todo List App by Flutter
hey guys I am making a Todo list app in Flutter, I create a void function which called "checkBoxCallBack" and want to use it in a Checkbox onChanged property and i got this error that i wrote down, i trained by angela yu大家好,我正在 Flutter 制作一个 Todo 列表应用程序,我创建了一个名为“checkBoxCallBack”的 void function,并想在 Checkbox onChanged 属性中使用它,我得到了这个我写下的错误,我由 angela yu 训练
error:错误:
Closure call with mismatched arguments: function '_TaskTileState.checkBoxCallBack'
Receiver: Closure: (bool) => void from Function 'checkBoxCallBack':.
Tried calling: _TaskTileState.checkBoxCallBack()
Found: _TaskTileState.checkBoxCallBack(bool) => void
my code is:我的代码是:
class TaskTile extends StatefulWidget {
const TaskTile({
Key? key,
}) : super(key: key);
@override
State<TaskTile> createState() => _TaskTileState();
}
class _TaskTileState extends State<TaskTile> {
bool isChecked = false;
void checkBoxCallBack(bool checkboxState) {
setState(() {
isChecked = checkboxState;
});
}
@override
Widget build(BuildContext context) {
return ListTile(
title: Text(
'This is a task',
style: TextStyle(
decoration: isChecked ? TextDecoration.lineThrough : null),
),
trailing: TaskCheckBox(
checkBoxState: isChecked,
toggleCheckboxState: checkBoxCallBack,
),
);
}
}
class TaskCheckBox extends StatelessWidget {
final bool checkBoxState;
final Function toggleCheckboxState;
TaskCheckBox(
{required this.checkBoxState, required this.toggleCheckboxState});
@override
Widget build(BuildContext context) {
return Checkbox(
value: checkBoxState,
onChanged: toggleCheckboxState(),
);
}
}
}
I found my problem我发现了我的问题
here is the fixed code:这是固定代码:
Checkbox(
value: checkBoxState,
onChanged: (bool? value) => toggleCheckboxState(value!),
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.