user_info.dart 5.1 KB

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