Complete the code to declare a Dart class named User.
class [1] { final String name; final int age; User(this.name, this.age); }
The class name must be User to match the constructor and usage.
Complete the factory constructor to create a User from JSON.
factory User.fromJson(Map<String, dynamic> json) {
return User(
json['[1]'],
json['age'],
);
}The JSON key for the user's name is name, matching the class field.
Fix the error in the toJson method to return a Map.
Map<String, dynamic> toJson() {
return {
'name': name,
'age': [1],
};
}The age field is an int and should be returned directly, not converted to string or called as a method.
Fill both blanks to complete the User class with fromJson and toJson methods.
class User { final String name; final int age; User(this.name, this.age); factory User.[1](Map<String, dynamic> json) { return User(json['name'], json['age']); } Map<String, dynamic> [2]() { return {'name': name, 'age': age}; } }
The factory constructor is named fromJson and the method to convert to JSON is toJson.
Fill all three blanks to create a list of User objects from JSON list.
List<User> users = (jsonList as List).map(([1]) => User.[2]([3])).toList();
The variable name in the map function is item, used twice. The factory constructor is fromJson.
