person.dart 666 B

12345678910111213141516171819202122232425262728
  1. import 'dart:convert';
  2. class Person {
  3. String firstname;
  4. String lastname;
  5. int age;
  6. String gender;
  7. String image;
  8. Person(this.firstname, this.lastname, this.age, this.gender, this.image);
  9. String toJson() {
  10. Map<String, dynamic> map = Map<String, dynamic>();
  11. map['firstname'] = this.firstname;
  12. map['lastname'] = this.lastname;
  13. map['age'] = this.age;
  14. map['gender'] = this.gender;
  15. map['image'] = this.image;
  16. return jsonEncode(map);
  17. }
  18. static Person fromJson(String json) {
  19. Map<String, dynamic> map = jsonDecode(json);
  20. return Person(map['firstname'], map['lastname'], map['age'], map['gender'], map['image']);
  21. }
  22. }