Issue
How do I create an inline function to fix this error:
The argument type 'void Function()' can't be assigned to the parameter type 'void Function.
Consider the following code:
Switch(value: _showChart, onChanged: () { //this generates the error
setState(() {
_showChart = value;
});
},)
If I extracted it to a function it would look something like this, but I don't want to do that:
VoidCallback? onSwitch(val){
setState(() {
_showChart = val;
});
}
Is there a way to do that inline?
Solution
onChanged: contains a value parameter.
You are missing a typo, the value parameter. It will be,
Switch(
value: true,
onChanged: (value) {
setState(() {
_showChart = value;
});
},
),
Answered By - Yeasin Sheikh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.