I’m new to flutter development, at starting everything was well and good, but now everytime i run apy app i’m getting the following error. Please show me some ways to fix it.
C:/Users/Admin/AppData/Local/Pub/Cache/hosted/pub.dev/material_color_utilities-0.8.0/lib/palettes/tonal_palette.dart:164:30: Error: The argument type 'double?' can't be assigned to the parameter type 'double' because 'double?' is nullable and 'double' isn't.
tone, () => Hct.from(_hue, chroma, tone.toDouble()).toInt());
^
/C:/Users/Admin/AppData/Local/Pub/Cache/hosted/pub.dev/material_color_utilities-0.8.0/lib/palettes/tonal_palette.dart:164:36: Error: The argument type 'double?' can't be assigned to the parameter type 'double' because 'double?' is nullable and 'double' isn't.
tone, () => Hct.from(_hue, chroma, tone.toDouble()).toInt());
^
/C:/Users/Admin/AppData/Local/Pub/Cache/hosted/pub.dev/collection-1.18.0/lib/src/canonicalized_map.dart:175:47: Error: Method 'call' cannot be called on 'bool Function(K)?' because it is potentially null.
Try calling using ?. instead.
(_isValidKeyFn == null || _isValidKeyFn.call(key) ?? false);
^^^^
Failed to compile application.
I have tried ‘dart fix –apply’, also tried to do some modification mentioned in chatgpt, but nothing seems working for me. maybe i’m doing some mistakes.
2
Answers
The reason is that nullable types and their non-nullable analogs are different types in dart types system.
While converting nullable type to non-nullable you should do one of two things:
Read more details here Dart: understanding null safety
that’s because you don’t use null safety correctly.
the meaning of
double?
is same asdouble or null
and the methodstoDouble
andtoInt
cannot be used on null so this is the reason for the compile error.for the second error I failed to understand your intensions
if you want to return true when the function _isValidKeyFn is null but false when the function is not null but have return type of null
then the right expression is: (notice the ! after _isValidKeyFn)
but if your intension is to return false even if the function is actually null, then the right expression is: