【发布时间】:2021-12-31 12:05:15
【问题描述】:
当我在制作应用程序时发生错误说-参数类型'Function'不能分配给参数类型'void Function(bool?)?'。 onChanged : toggleCheckState 的 Taskcheckbox 无状态小部件内部表示无法分配函数 toggleCheckboxState。
class task_tile extends StatefulWidget {
@override
State<task_tile> createState() => _task_tileState();
}
class _task_tileState extends State<task_tile> {
bool ischanged = false;
@override
Widget build(BuildContext context) {
return ListTile(
title: Text("This is a box",style: TextStyle(
decoration: ischanged ? TextDecoration.lineThrough:null
),
),
trailing: Taskcheckbox(ischanged,(bool checkboxState) {
setState(() {
ischanged = checkboxState;
});
}),
);
}
}
class Taskcheckbox extends StatelessWidget {
final bool checkboxState;
final Function toggleCheckboxState;
Taskcheckbox(this.checkboxState,this.toggleCheckboxState);
@override
Widget build(BuildContext context) {
return Checkbox(
activeColor: Colors.lightBlueAccent,
value: checkboxState,
onChanged:toggleCheckboxState,
);
}
}
【问题讨论】:
-
需要更改声明检查答案。请。
标签: flutter dart flutter-layout flutter-dependencies