marco.pms.mobileapp/lib/model/employees/employee_with_id_name_model.dart

31 lines
771 B
Dart

class EmployeeModelWithIdName {
final String id;
final String firstName;
final String lastName;
final String name;
EmployeeModelWithIdName({
required this.id,
required this.firstName,
required this.lastName,
required this.name,
});
factory EmployeeModelWithIdName.fromJson(Map<String, dynamic> json) {
return EmployeeModelWithIdName(
id: json['id']?.toString() ?? '',
firstName: json['firstName'] ?? '',
lastName: json['lastName'] ?? '',
name: '${json['firstName'] ?? ''} ${json['lastName'] ?? ''}'.trim(),
);
}
Map<String, dynamic> toJson() {
return {
'id': id,
'firstName': name.split(' ').first,
'lastName': name.split(' ').length > 1 ? name.split(' ').last : '',
};
}
}