user.dart 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. import 'package:sport/services/Converter.dart';
  2. class User {
  3. int? id;
  4. int? userId;
  5. int? gameId;
  6. num? score;
  7. int? provinceId;
  8. int? cityId;
  9. int? districtId;
  10. String? finishAt;
  11. int? duration;
  12. int? consume;
  13. int? up;
  14. int? upNew;
  15. String? rateBegin;
  16. String? rateEnd;
  17. String? userName;
  18. String? userAvatar;
  19. int? userLevel;
  20. String? userLevelLogo;
  21. int? userGender;
  22. int? userAge;
  23. int? position;
  24. int? sportDay;
  25. List<Achievement>? achievements;
  26. User(
  27. {this.id,
  28. this.userId,
  29. this.gameId,
  30. this.score,
  31. this.provinceId,
  32. this.cityId,
  33. this.districtId,
  34. this.finishAt,
  35. this.duration,
  36. this.consume,
  37. this.up,
  38. this.upNew,
  39. this.rateBegin,
  40. this.rateEnd,
  41. this.userName,
  42. this.userAvatar,
  43. this.userLevel,
  44. this.userLevelLogo,
  45. this.userGender,
  46. this.userAge,
  47. this.position,
  48. this.achievements});
  49. User.fromJson(Map<String, dynamic> json) {
  50. id = json['id'];
  51. userId = json['user_id'];
  52. gameId = json['game_id'];
  53. score = json['score'];
  54. provinceId = json['province_id'];
  55. cityId = json['city_id'];
  56. districtId = json['district_id'];
  57. finishAt = json['finish_at'];
  58. duration = json['duration'];
  59. consume = json['consume'];
  60. up = json['up'];
  61. upNew = Converter.toInt(json['up_new']);
  62. rateBegin = json['rate_begin'];
  63. rateEnd = json['rate_end'];
  64. userName = json['user_name'];
  65. userAvatar = json['user_avatar'];
  66. userLevel = json['user_level'];
  67. userLevelLogo = json['user_level_logo'];
  68. userGender = json['user_gender'];
  69. userAge = json['user_age'];
  70. position = json['position'];
  71. sportDay = json['sport_day'] ?? 0;
  72. if (json['achievements'] != null) {
  73. achievements = [];
  74. json['achievements'].forEach((v) {
  75. achievements!.add(new Achievement.fromJson(v));
  76. });
  77. }
  78. }
  79. Map<String, dynamic> toJsonSimple() {
  80. final Map<String, dynamic> data = new Map<String, dynamic>();
  81. data['id'] = this.userId;
  82. data['nickname'] = this.userName;
  83. data['gender'] = this.userGender;
  84. data['avatar'] = this.userAvatar?.replaceAll("http://", "https://");
  85. return data;
  86. }
  87. Map<String, dynamic> toJson() {
  88. final Map<String, dynamic> data = new Map<String, dynamic>();
  89. data['id'] = this.id;
  90. data['user_id'] = this.userId;
  91. data['game_id'] = this.gameId;
  92. data['score'] = this.score;
  93. data['province_id'] = this.provinceId;
  94. data['city_id'] = this.cityId;
  95. data['district_id'] = this.districtId;
  96. data['finish_at'] = this.finishAt;
  97. data['duration'] = this.duration;
  98. data['consume'] = this.consume;
  99. data['up'] = this.up;
  100. data['up_new'] = this.upNew;
  101. data['rate_begin'] = this.rateBegin;
  102. data['rate_end'] = this.rateEnd;
  103. data['user_name'] = this.userName;
  104. data['user_avatar'] = this.userAvatar;
  105. data['user_level'] = this.userLevel;
  106. data['user_level_logo'] = this.userLevelLogo;
  107. data['user_gender'] = this.userGender;
  108. data['user_age'] = this.userAge;
  109. data['position'] = this.position;
  110. data['sport_day'] = this.sportDay;
  111. if (this.achievements != null) {
  112. data['achievements'] = this.achievements!.map((v) => v.toJson()).toList();
  113. }
  114. return data;
  115. }
  116. }
  117. class Achievement {
  118. int? id;
  119. int? seriesId;
  120. String? logo;
  121. String? name;
  122. int? rewardExp;
  123. int? rewardScore;
  124. int conditionCount = 0;
  125. int conditionProgress = 0;
  126. int? userId;
  127. String? createdAt;
  128. String? conditionDetail;
  129. String? conditionMeasure;
  130. int? userCount;
  131. int? seriesCount;
  132. String? seriesName;
  133. // int? conditionCount;
  134. // int? conditionProgress;
  135. Achievement({
  136. this.id,
  137. this.seriesId,
  138. this.logo,
  139. this.name,
  140. this.rewardExp,
  141. this.rewardScore,
  142. this.conditionCount = 0,
  143. this.conditionProgress = 0,
  144. this.createdAt,
  145. this.conditionDetail,
  146. this.conditionMeasure,
  147. this.userCount,
  148. this.seriesCount,
  149. this.seriesName,
  150. // this.conditionCount,
  151. // this.conditionProgress,
  152. });
  153. Achievement.fromJson(Map<String, dynamic> json) {
  154. id = json['id'];
  155. userId = json['user_id'];
  156. seriesId = json['series_id'];
  157. logo = json['logo'];
  158. name = json['name'];
  159. rewardExp = json['reward_exp'];
  160. rewardScore = json['reward_score'];
  161. conditionCount = json['condition_count'] ?? 0;
  162. conditionProgress = json['condition_progress'] ?? 0;
  163. createdAt = json['created_at'] == null ? "" : json['created_at'];
  164. conditionDetail = json['condition_detail'];
  165. conditionMeasure = json['condition_measure'];
  166. userCount = json['user_count'];
  167. seriesCount = json['series_count'];
  168. seriesName = json['series_name'];
  169. // conditionProgress = json['condition_progress'];
  170. // conditionCount = json['condition_count'];
  171. }
  172. Map<String, dynamic> toJson() {
  173. final Map<String, dynamic> data = new Map<String, dynamic>();
  174. data['id'] = this.id;
  175. data['user_id'] = this.userId;
  176. data['series_id'] = this.seriesId;
  177. data['logo'] = this.logo;
  178. data['name'] = this.name;
  179. data['reward_exp'] = this.rewardExp;
  180. data['reward_score'] = this.rewardScore;
  181. data['condition_count'] = this.conditionCount;
  182. data['condition_progress'] = this.conditionProgress;
  183. data['created_at'] = this.createdAt;
  184. data['condition_detail'] = this.conditionDetail;
  185. data['condition_measure'] = this.conditionMeasure;
  186. data['user_count'] = this.userCount;
  187. data['series_count'] = this.seriesCount;
  188. data['series_name'] = this.seriesName;
  189. // data['condition_progress'] = this.conditionProgress;
  190. // data['condition_count'] = this.conditionCount;
  191. return data;
  192. }
  193. }
  194. //class Achievement {
  195. // int? id;
  196. // String? name;
  197. // String? logo;
  198. // int? conditionSportDuration;
  199. // int? sort;
  200. // int? seriesId;
  201. // int? rewardScore;
  202. //
  203. // Achievement(
  204. // {this.id,
  205. // this.name,
  206. // this.logo,
  207. // this.conditionSportDuration,
  208. // this.sort,
  209. // this.seriesId,
  210. // this.rewardScore});
  211. //
  212. // Achievement.fromJson(Map<String, dynamic> json) {
  213. // id = json['id'];
  214. // name = json['name'];
  215. // logo = json['logo'];
  216. // conditionSportDuration = json['condition_sport_duration'] == null ? json['condition_duration'] : json['condition_sport_duration'];
  217. // sort = json['sort'];
  218. // seriesId = json['series_id'];
  219. // rewardScore = json['reward_score'];
  220. // }
  221. //
  222. // Map<String, dynamic> toJson() {
  223. // final Map<String, dynamic> data = new Map<String, dynamic>();
  224. // data['id'] = this.id;
  225. // data['name'] = this.name;
  226. // data['logo'] = this.logo;
  227. // data['condition_sport_duration'] = this.conditionSportDuration;
  228. // data['sort'] = this.sort;
  229. // data['series_id'] = this.seriesId;
  230. // data['reward_score'] = this.rewardScore;
  231. // return data;
  232. // }
  233. //}