You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A parameter is either always optional or always required. That does not depend on the its type.
If the parameter is required, then you need to pass a valid value, whether the parameter is nullable or not. If it is nullable, then null is a valid value, but no more special than any other valid value.
You are not forced to pass null to Test<num?>(null), you could also use Test<num?>(0)
If the parameter is optional, it's either nullable or it has a default value. When the type of the parameter is a type variable, then it's not possible to have a default value (there is no value which is valid for all types that can be the type argument), so the parameter must either be made definitely nullable (typed as T?) or it must be required.
We did think about whether we could combine nullability and optionality in parameters, but did not find a good model that everybody could agree on.
So I'm on Dart 2.12, and I've run into a scenario where I have to feed
null
into a constructor, even though the parameter should be nullable.The
nullable
variable needsnull
in order to get initialized which makes sense since the constructor takes a required argument.What doesn't make sense though, is that even though I can inject my nullable types into the class, the constructor argument CANNOT be optional.
Wouldn't it make sense that the analyzer ignores types that originate from outside the class, since it cannot know whether they're nullable or not?
IMO only if the type
extends
some kind of actual type, can the Test class start making assumptions towards nullability.The text was updated successfully, but these errors were encountered: