user_info.dart 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. if(json.containsKey("uid")){
  47. id = Converter.toInt(json['uid']);
  48. }
  49. name = json['name'] ?? json['user_name'];
  50. avatar = json['avatar'] ?? json['user_avatar'];
  51. sportTargetId = json['sport_target_id'];
  52. topSubjectId = json['top_subject_id'];
  53. level = Converter.toInt(json['level']);
  54. score = Converter.toDouble(json['score']);
  55. isBan = Converter.toInt(json['is_ban']);
  56. provinceId = Converter.toInt(json['province_id']);
  57. cityId = Converter.toInt(json['city_id']);
  58. districtId = Converter.toInt(json['district_id']);
  59. createdAt = json['created_at'];
  60. gender = Converter.toInt(json['gender']);
  61. age = Converter.toInt(json['age']);
  62. province = json['province'];
  63. city = json['city'];
  64. district = json['district'];
  65. sportRecordSum = json['sport_record_sum'] != null
  66. ? new SportRecordSum.fromJson(json['sport_record_sum'])
  67. : null;
  68. if (json['achievements_show'] != null) {
  69. achievements = new List<Achievement>();
  70. json['achievements_show'].forEach((v) {
  71. achievements.add(new Achievement.fromJson(v));
  72. });
  73. }
  74. followStatus= json['follow_status'];
  75. }
  76. Map<String, dynamic> toJson() {
  77. final Map<String, dynamic> data = new Map<String, dynamic>();
  78. data['id'] = this.id;
  79. data['name'] = this.name;
  80. data['avatar'] = this.avatar;
  81. data['sport_target_id'] = this.sportTargetId;
  82. data['top_subject_id'] = this.topSubjectId;
  83. data['level'] = this.level;
  84. data['score'] = this.score;
  85. data['is_ban'] = this.isBan;
  86. data['province_id'] = this.provinceId;
  87. data['city_id'] = this.cityId;
  88. data['district_id'] = this.districtId;
  89. data['created_at'] = this.createdAt;
  90. data['gender'] = this.gender;
  91. data['age'] = this.age;
  92. data['province'] = this.province;
  93. data['city'] = this.city;
  94. data['district'] = this.district;
  95. if (this.sportRecordSum != null) {
  96. data['sport_record_sum'] = this.sportRecordSum.toJson();
  97. }
  98. if (this.achievements != null) {
  99. data['achievements_show'] = this.achievements.map((v) => v.toJson()).toList();
  100. }
  101. data['follow_status'] = this.followStatus;
  102. return data;
  103. }
  104. bool isFriend(){
  105. return followStatus == "friends" || followStatus == "followed";
  106. }
  107. }
  108. class SportRecordSum {
  109. int id;
  110. int userId;
  111. int consume;
  112. int duration;
  113. int jumpCount;
  114. int crouchCount;
  115. SportRecordSum(
  116. {this.id,
  117. this.userId,
  118. this.consume,
  119. this.duration,
  120. this.jumpCount,
  121. this.crouchCount});
  122. SportRecordSum.fromJson(Map<String, dynamic> json) {
  123. id = json['id'];
  124. userId = json['user_id'];
  125. consume = json['consume'];
  126. duration = json['duration'];
  127. jumpCount = json['jump_count'];
  128. crouchCount = json['crouch_count'];
  129. }
  130. Map<String, dynamic> toJson() {
  131. final Map<String, dynamic> data = new Map<String, dynamic>();
  132. data['id'] = this.id;
  133. data['user_id'] = this.userId;
  134. data['consume'] = this.consume;
  135. data['duration'] = this.duration;
  136. data['jump_count'] = this.jumpCount;
  137. data['crouch_count'] = this.crouchCount;
  138. return data;
  139. }
  140. }