freezed
freezed copied to clipboard
Make Fields non nullale provided with Default value.
In the following code, I'd like the parameters to be nullable. This means that when I pass null or nothing to the parameters, default values should be used.
@freezed
class User with _$User {
factory User({
@Default(0) int? id,
@Default("") String? userName,
@Default("") String? image,
@Default("") String? token,
}) = _User;
}
Currently, when I implement this, it functions correctly. However, since default values are already provided, the generated code should not include nullable fields.
For example:
User user = User();
user.id // This field should not be nullable, as default values have already been provided.
Basically I don't want to use non nullable operator in UI.
user.id!
@rrousselGit please help with suggestion
No, it should be nullable if we pass null
to it.
For example, the maxLine property is default to 1, however, we can pass null
and its behavior changed.