How to resolve The argument type ‘TextStyle?’ can’t be assigned to the parameter type ‘TextStyle’

I am getting this null safety error while working on my flutter app.

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

Here is the code snippet that is throwing this error:

ButtonStyle(textStyle: MaterialStateProperty.all<TextStyle>(Theme.of(context).textTheme.button))

Since I am using VS Code it is suggesting me this solution to put not operator at the end of the argument.

ButtonStyle(textStyle: MaterialStateProperty.all<TextStyle>(Theme.of(context).textTheme.button!))

Is this a good practice to use ! in my code and what other solutions are possible in this case?



Read more here: https://stackoverflow.com/questions/66273180/how-to-resolve-the-argument-type-textstyle-cant-be-assigned-to-the-parameter

Content Attribution

This content was originally published by Kashish Khullar at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: