Search
⚠️

void Funcition() Error

Problem [The argument type 'dynamic Function(int)' can't be assigned to the parameter type 'void Function(dynamic)']
This error appears when the user defines the wrong Type for the variables.
Solution 1
Try to change the parameter type to VoidCallback
class _BottomHalf extends StatelessWidget { final int currentNum; final VoidCallback onChanged; // change it to VoidCallback const _BottomHalf({ required this.currentNum, required this.onChanged, Key? key, }) : super(key: key); // Build ... }
Dart
복사
Solution 2 [The argument type 'void Function()' can't be assigned to the parameter type 'void Function(int)]
If Solution 1 returns an error message of Error , try…
1.
By using cmd + LClick or RClick => Go TO => Declaration or Usages, move to the Usages
2.
Again, with the same method used in Step 1, move to the Declaration
3.
Look for the Type (e.g. ValueChanged)
4.
Change the parameter type
class _BottomHalf extends StatelessWidget { final int currentNum; final ValueChanged onChanged; // change it to VoidCallback const _BottomHalf({ required this.currentNum, required this.onChanged, Key? key, }) : super(key: key); // Build ... }
Dart
복사
Solution 3 [The argument type 'dynamic Function(int)' can't be assigned to the parameter type 'void Function(dynamic)']
1.
Change void to dynamic
dynamic onNumChanged(int val) { // changed from void => dynamic setState(() { currentNum = val; }); }
Dart
복사

Reference