user_info.dart 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import 'package:sport/bean/user.dart';
  2. import 'package:sport/services/Converter.dart';
  3. class UserInfo {
  4. int id;
  5. String name;
  6. String avatar;
  7. int sportTargetId;
  8. int topSubjectId;
  9. int level;
  10. double score;
  11. int isBan;
  12. int provinceId;
  13. int cityId;
  14. int districtId;
  15. String createdAt;
  16. int gender;
  17. int age;
  18. String province;
  19. String city;
  20. String district;
  21. SportRecordSum sportRecordSum;
  22. List<Achievement> achievements;
  23. String followStatus;
  24. UserInfo(
  25. {this.id,
  26. this.name,
  27. this.avatar,
  28. this.sportTargetId,
  29. this.topSubjectId,
  30. this.level,
  31. this.score,
  32. this.isBan,
  33. this.provinceId,
  34. this.cityId,
  35. this.districtId,
  36. this.createdAt,
  37. this.gender,
  38. this.age,
  39. this.province,
  40. this.city,
  41. this.district,
  42. this.sportRecordSum,
  43. this.achievements});
  44. UserInfo.fromJson(Map<String, dynamic> json) {
  45. id = Converter.toInt(json['id']);
  46. name = json['name'] ?? json['user_name'];
  47. avatar = json['avatar'] ?? json['user_avatar'];
  48. sportTargetId = json['sport_target_id'];
  49. topSubjectId = json['top_subject_id'];
  50. level = Converter.toInt(json['level']);
  51. score = Converter.toDouble(json['score']);
  52. isBan = Converter.toInt(json['is_ban']);
  53. provinceId = Converter.toInt(json['province_id']);
  54. cityId = Converter.toInt(json['city_id']);
  55. districtId = Converter.toInt(json['district_id']);
  56. createdAt = json['created_at'];
  57. gender = Converter.toInt(json['gender']);
  58. age = Converter.toInt(json['age']);
  59. province = json['province'];
  60. city = json['city'];
  61. district = json['district'];
  62. sportRecordSum = json['sport_record_sum'] != null
  63. ? new SportRecordSum.fromJson(json['sport_record_sum'])
  64. : null;
  65. if (json['achievements_show'] != null) {
  66. achievements = new List<Achievement>();
  67. json['achievements_show'].forEach((v) {
  68. achievements.add(new Achievement.fromJson(v));
  69. });
  70. }
  71. followStatus= json['follow_status'];
  72. }
  73. Map<String, dynamic> toJson() {
  74. final Map<String, dynamic> data = new Map<String, dynamic>();
  75. data['id'] = this.id;
  76. data['name'] = this.name;
  77. data['avatar'] = this.avatar;
  78. data['sport_target_id'] = this.sportTargetId;
  79. data['top_subject_id'] = this.topSubjectId;
  80. data['level'] = this.level;
  81. data['score'] = this.score;
  82. data['is_ban'] = this.isBan;
  83. data['province_id'] = this.provinceId;
  84. data['city_id'] = this.cityId;
  85. data['district_id'] = this.districtId;
  86. data['created_at'] = this.createdAt;
  87. data['gender'] = this.gender;
  88. data['age'] = this.age;
  89. data['province'] = this.province;
  90. data['city'] = this.city;
  91. data['district'] = this.district;
  92. if (this.sportRecordSum != null) {
  93. data['sport_record_sum'] = this.sportRecordSum.toJson();
  94. }
  95. if (this.achievements != null) {
  96. data['achievements_show'] = this.achievements.map((v) => v.toJson()).toList();
  97. }
  98. data['follow_status'] = this.followStatus;
  99. return data;
  100. }
  101. bool isFriend(){
  102. return followStatus == "friends" || followStatus == "followed";
  103. }
  104. }
  105. class SportRecordSum {
  106. int id;
  107. int userId;
  108. int consume;
  109. int duration;
  110. int jumpCount;
  111. int crouchCount;
  112. SportRecordSum(
  113. {this.id,
  114. this.userId,
  115. this.consume,
  116. this.duration,
  117. this.jumpCount,
  118. this.crouchCount});
  119. SportRecordSum.fromJson(Map<String, dynamic> json) {
  120. id = json['id'];
  121. userId = json['user_id'];
  122. consume = json['consume'];
  123. duration = json['duration'];
  124. jumpCount = json['jump_count'];
  125. crouchCount = json['crouch_count'];
  126. }
  127. Map<String, dynamic> toJson() {
  128. final Map<String, dynamic> data = new Map<String, dynamic>();
  129. data['id'] = this.id;
  130. data['user_id'] = this.userId;
  131. data['consume'] = this.consume;
  132. data['duration'] = this.duration;
  133. data['jump_count'] = this.jumpCount;
  134. data['crouch_count'] = this.crouchCount;
  135. return data;
  136. }
  137. }