Consider this code
class Album {
int userId;
int id;
String title;
Album({this.userId, this.id, this.title});
Album.fromJsonN(Map<String, dynamic> json) {
this.userId = json['userId'];
this.id = json['id'];
this.title = json['title'];
}
factory Album.fromJson(Map<String, dynamic> json) {
return Album(userId: json['userId'], id: json['id'], title: json['title']);
}
}
In most tutorials the explanation for why we use factory for json mapping method is: "we use the factory keyword when implementing a constructor that doesn’t always create a new instance of its class".
in factory method in above code, doesn't it returning a new instance? if it does, so whats the reason for using factory here? and whats the difference between factory constructor and fromJsonN named constructor in this context?