Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Fields non nullale provided with Default value. #1047

Open
f1forhelp opened this issue Mar 12, 2024 · 2 comments
Open

Make Fields non nullale provided with Default value. #1047

f1forhelp opened this issue Mar 12, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@f1forhelp
Copy link

f1forhelp commented Mar 12, 2024

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!
@f1forhelp f1forhelp added enhancement New feature or request needs triage labels Mar 12, 2024
@f1forhelp f1forhelp changed the title Make Fields non nullale provvided with Default value. Make Fields non nullale provided with Default value. Mar 12, 2024
@f1forhelp
Copy link
Author

@rrousselGit please help with suggestion

@Cierra-Runis
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants