Created
December 5, 2019 14:11
-
-
Save fabiojansenbr/d5a8cc751e633e5e7d17750036cd7d3a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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