I've tried to create a profile model like this; fromJson
looks good, but I have a problem with toJson
:
@Freezed(
fromJson: true,
toJson: true,
map: FreezedMapOptions.none,
when: FreezedWhenOptions.none,
)
class ProfileAttribute with _$ProfileAttribute {
const factory ProfileAttribute({
@JsonKey(name: '_id', includeIfNull: false) final String? id,
final String? uid,
final String? username,
final String? name,
final String? phone,
final String? email,
final String? address,
final String? image,
}) = _ProfileAttribute;
factory ProfileAttribute.fromJson(Map<String, dynamic> json) =>
_$ProfileAttributeFromJson(json);
}
I see on debug toJson will send:
"attributes": {
"_id": null,
"uid": null,
"username": null,
"name": null,
"phone": null,
"email": "[email protected]",
"address": null,
"image": null
}
In this case, I just want to send email to backend like:
"attributes": {
"email": "[email protected]"
}
How to ignore null value in toJson
?