lundi 14 juin 2021

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

here is my code and error is after fluttre update to 2.13 version so please help.... error is on TaskCheckBox class onchanged method and dart analys return The argument type 'Function' can't be assigned to the parameter type 'void Function(bool?)?'.

class TaskTile extends StatefulWidget {
  @override
  _TaskTileState createState() => _TaskTileState();
}

class _TaskTileState extends State<TaskTile> {
  bool isChecked = false;

  @override
  Widget build(BuildContext context) {
    return ListTile(
      title: Text(
        'This is task.',
        style: TextStyle(
          decoration: isChecked ? TextDecoration.lineThrough : null,
        ),
      ),
      trailing: TaskCheckBox(checkboxState: isChecked,toggleCheckboxState: (bool checkboxState) {
        setState(() {
          isChecked = checkboxState;
        });
      }),
    );
  }
}

class TaskCheckBox extends StatelessWidget {
  final bool checkboxState;
  final Function toggleCheckboxState;

  TaskCheckBox({required this.checkboxState,required this.toggleCheckboxState});

  @override
  Widget build(BuildContext context) {
    return Checkbox(
      activeColor: Colors.lightBlueAccent,
      value: checkboxState,
      onChanged: toggleCheckboxState,
    );
  }
}



Aucun commentaire:

Enregistrer un commentaire