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

Default value for record fields #1340

Open
Johannes5000 opened this issue Jul 26, 2023 · 0 comments
Open

Default value for record fields #1340

Johannes5000 opened this issue Jul 26, 2023 · 0 comments

Comments

@Johannes5000
Copy link

Since Version 6.7.0 Records are supported.

If I am right, there is currently no possibility to set a default value for a field inside the record.

For example:

@JsonSerializable()
class MyClass {
  final ({
    double numberWithDefault,
    String someOtherText,
  }) myRecord;

  @JsonKey(defaultValue: 0.0)
  final double anotherNumberWithDefault;

  MyClass({
    required this.myRecord,
    required this.anotherNumberWithDefault,
  });

  factory MyClass.fromJson(Map<String, dynamic> json) => _$MyClassFromJson(json);
  Map<String, dynamic> toJson() => _$MyClassToJson(this);
}

It would be nice to be able to set numberWithDefault to a default value, if the json value is null (just like anotherNumberWithDefault).

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

No branches or pull requests

1 participant