data_tables icon indicating copy to clipboard operation
data_tables copied to clipboard

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

Open Shubham-Narkhede opened this issue 4 years ago • 3 comments

Hi i'm using this library and when I integret it with my code then it gives this type of error i dont knw why im getting this please help mi.

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

     onSelectChanged: (bool value) {
                  if (dessert.selected != value) {
                    setState(() {
                      dessert.selected = value;
                    });
                  }
                },

Shubham-Narkhede avatar Sep 14 '21 10:09 Shubham-Narkhede

@Shubham-Narkhede The problem is the boolean, which get's passed into your function, it may be null.

Reason for that is the following code:

onChanged: (bool? value) {
                                            setState(() {
                                              widget.rows[index].onSelectChanged!(value);
                                            });
                                          },

Look here for reference: data_tables

So you're code must look like the following:

onSelectChanged: (bool? value) {
                  if (dessert.selected != value) {
                    setState(() {
                      dessert.selected = value;
                    });
                  }
                },

jayjah avatar Nov 03 '21 16:11 jayjah

Could you open a PR?

rodydavis avatar Nov 03 '21 17:11 rodydavis

@rodydavis do you mean to make this one explizit not-nullable? So that the version off @Shubham-Narkhede is valid?

jayjah avatar Nov 04 '21 17:11 jayjah