The argument type 'TextStyle?' can't be assigned to the parameter type 'TextStyle'

1.2k Views Asked by At

I am getting this error...

code snippet that is throwing this error:

catalog.desc.text.textStyle(context.captionStyle).make(),

1

There are 1 best solutions below

0
On BEST ANSWER

Your object context.captionStyle has the TextStyle? type, which means it can be null. The .textStyle() function only accepts TextStyle objects, hence the error.

You either have to make sure that context.captionStyle is not null before trying to pass it to .textStyle(), or assuring the compiler it will never be null by writing .textStyle(context.captionStyle!) (but you will still get an error if it becomes null somehow).