jeudi 7 octobre 2021

type '(bool?) => Null' is not a subtype of type 'bool?'

I created a custom checkbox calling it where i need.

here is the custom checkbox code

Widget checkboxCustom(context, value,onchange, ) {
  return Checkbox(
    activeColor: HexColor("#5344ed"),
    side: BorderSide(color: HexColor("#6e6b7b")),
    shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)),
    value: value,
    onChanged: onchange,
  );
}

and calling it like this

checkboxCustom(context,
            (bool? selected) {
            if(selected!=null)
            {
             setState(() {
                 onCategorySelected(selected,book.id);
             });
        }
      },
      _selecteCategorys
  ),
  void _onCategorySelected(bool? selected, category_id) {
    if (selected == true) {
      setState(() {
        _selecteCategorys.add(category_id);
      });
    } else {
      setState(() {
        _selecteCategorys.remove(category_id);
      });
    }
  }

but it gives me this error


════════ Exception caught by widgets library ═══════════════════════════════════
type '(bool?) => Null' is not a subtype of type 'bool?'

i removed the ? from bool but still same error, please help how to do this.




Aucun commentaire:

Enregistrer un commentaire