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 json) { return EmployeeModelWithIdName( id: json['id']?.toString() ?? '', firstName: json['firstName'] ?? '', lastName: json['lastName'] ?? '', name: '${json['firstName'] ?? ''} ${json['lastName'] ?? ''}'.trim(), ); } Map toJson() { return { 'id': id, 'firstName': name.split(' ').first, 'lastName': name.split(' ').length > 1 ? name.split(' ').last : '', }; } }