user.dart 6.3 KB

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