Skip to content

Instantly share code, notes, and snippets.

@fabiojansenbr
Created December 5, 2019 14:11
Show Gist options
  • Save fabiojansenbr/d5a8cc751e633e5e7d17750036cd7d3a to your computer and use it in GitHub Desktop.
Save fabiojansenbr/d5a8cc751e633e5e7d17750036cd7d3a to your computer and use it in GitHub Desktop.
import 'dart:convert';
List<Employee> employeeFromJson(String str) =>
List<Employee>.from(json.decode(str).map((x) => Employee.fromJson(x)));
String employeeToJson(List<Employee> data) =>
json.encode(List<dynamic>.from(data.map((x) => x.toJson())));
class Employee {
int id;
String email;
String firstName;
String lastName;
String avatar;
Employee({
this.id,
this.email,
this.firstName,
this.lastName,
this.avatar,
});
factory Employee.fromJson(Map<String, dynamic> json) => Employee(
id: json["id"],
email: json["email"],
firstName: json["firstName"],
lastName: json["lastName"],
avatar: json["avatar"],
);
Map<String, dynamic> toJson() => {
"id": id,
"email": email,
"firstName": firstName,
"lastName": lastName,
"avatar": avatar,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment