'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

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(),
    );
  }
}

    }


Solution 1:[1]

I found my problem

here is the fixed code :

Checkbox(
      value: checkBoxState,
      onChanged: (bool? value) => toggleCheckboxState(value!),
    );

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ArVaN903