Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The argument type 'Function' can't be assigned to the parameter type 'void Function(bool?)

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

While i was making an app an error occured says- The argument type ‘Function’ can’t be assigned to the parameter type ‘void Function(bool?)?’. inside Taskcheckbox stateless widget at onChanged:toggleCheckState says the function toggleCheckboxState can’t be assigned.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You need to chnage your function type to solve this issue

From

final Function toggleCheckboxState;

To

final ValueChanged<bool?> toggleCheckboxState;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading