Issue
I want to create a nested field with the type of map. 'usersName' is the field that has the type of map, contain 'firstName' and 'lastName'. Here is the image:
If you need a source code, tell me. Thank you
user_model.dart
class User {
String id;
String name;
String email;
String password;
String phone;
User({
required this.id,
required this.name,
required this.email,
required this.password,
required this.phone,
});
//and i dont know how to make it work
}
Solution
You can create a UserName class with firstName and lastName variables and then on your User class you change your name from String to UserName.
class User {
String id;
UserName name;
String email;
String password;
String phone;
User({
required this.id,
required this.name,
required this.email,
required this.password,
required this.phone,
});
}
class UserName {
String firstName;
String lastName;
UserName({
required this.firstName,
required this.lastName,
});
}
Answered By - Henrique Zanferrari
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.