user_model.dart 574 B

1234567891011121314151617181920212223242526272829303132
  1. class UserModel {
  2. int id = 0;
  3. String userName = "";
  4. // String
  5. int sex = 0;
  6. int age = 18;
  7. UserModel({
  8. required this.id,
  9. required this.userName,
  10. required this.sex,
  11. required this.age,
  12. });
  13. static UserModel fromJson(Map<String, dynamic> json) {
  14. return UserModel(
  15. id: json['id'] ?? 0,
  16. userName: json['userName'] ?? "",
  17. sex: json['sex'] ?? 0,
  18. age: json['age'] ?? 18,
  19. );
  20. }
  21. Map<String, dynamic> toJson() {
  22. return {
  23. 'id': id,
  24. 'userName': userName,
  25. 'sex': sex,
  26. 'age': age,
  27. };
  28. }
  29. }