I can't understand the real purpose of factory constructors. I have this code that contains a method and a factory constructor:
User fromJJson(Map<String, dynamic> json) {
final user = User(
userName: json['userName'],
photoUrl: json['photoUrl'],
lastSeen: json['lastSeen'],
active: json['active'],
);
user._id = json['id'];
return user;
}
factory User.fromJson(Map<String, dynamic> json) {
final user = User(
userName: json['userName'],
photoUrl: json['photoUrl'],
lastSeen: json['lastSeen'],
active: json['active'],
);
user._id = json['id'];
return user;
}
What's the difference between the two above, they serve the exact same purpose, so what do factory constructors really do ?