In this model when i use freezed i'm missing toMap() method
I want change the company object into Map<String, String>
class Company {
final String? id;
final String? name;
Company({
this.id,
this.name,
});
Map<String, String> toMap() {
return {
'id': id!,
'name': name!,
};
}
factory Company.fromJson(Map<String, dynamic> json) {
return Company(
id: json['id'],
name: json['name'],
);
}
}
The
fromJson|toJsonmethods can be generated automatically based on your fields. I recommend that you pay attention to this section of the documentation - Freezed: FromJson/ToJsonYour model will end up looking something like this:
Now all you have to do is run the command in the console:
If you need exactly
toMap()method with that name, you can do it like this: