sport_step.dart 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import 'package:sport/services/Converter.dart';
  2. class SportStep {
  3. List<Record>? records;
  4. Sum? sum;
  5. List<int>? steps;
  6. SportStep({this.records, this.sum});
  7. SportStep.fromJson(Map<String, dynamic> json) {
  8. if (json['records'] != null) {
  9. records =[];
  10. json['records'].forEach((v) {
  11. records!.add(new Record.fromJson(v));
  12. });
  13. }
  14. steps =json['steps'] != null ? json['steps'].cast<int>() : <int>[];
  15. sum = json['sum'] != null ? new Sum.fromJson(json['sum']) : null;
  16. }
  17. Map<String, dynamic> toJson() {
  18. final Map<String, dynamic> data = new Map<String, dynamic>();
  19. if (this.records != null) {
  20. data['records'] = this.records!.map((v) => v.toJson()).toList();
  21. }
  22. if (this.sum != null) {
  23. data['sum'] = this.sum!.toJson();
  24. }
  25. return data;
  26. }
  27. }
  28. class Record {
  29. int? id;
  30. int? userId;
  31. int? step;
  32. int? distance;
  33. int? stepGame;
  34. int? stepDaily;
  35. int? stepJog;
  36. String? createdAt;
  37. int? year;
  38. int? month;
  39. Record(
  40. {this.id,
  41. this.userId,
  42. this.step,
  43. this.distance,
  44. this.stepGame,
  45. this.stepDaily,
  46. this.createdAt});
  47. Record.fromJson(Map<String, dynamic> json) {
  48. id = json['id'];
  49. userId = json['user_id'];
  50. step = json['step'];
  51. distance = json['distance'];
  52. stepGame = json['step_game'];
  53. stepDaily = json['step_daily'];
  54. stepJog = json['step_jog'];
  55. createdAt = json['created_at'];
  56. year = json['year'];
  57. month = json['month'];
  58. }
  59. Map<String, dynamic> toJson() {
  60. final Map<String, dynamic> data = new Map<String, dynamic>();
  61. data['id'] = this.id;
  62. data['user_id'] = this.userId;
  63. data['step'] = this.step;
  64. data['distance'] = this.distance;
  65. data['step_game'] = this.stepGame;
  66. data['step_daily'] = this.stepDaily;
  67. data['created_at'] = this.createdAt;
  68. data['step_jog'] = this.stepJog;
  69. return data;
  70. }
  71. }
  72. class Sum {
  73. double stepDayAvg = 0;
  74. int distance = 0;
  75. int step = 0;
  76. int stepDaily = 0;
  77. int stepGame = 0;
  78. int stepJog = 0;
  79. double stepRate= 0;
  80. double stepRateMax= 0;
  81. Sum(
  82. {this.stepDayAvg= 0,
  83. this.distance= 0,
  84. this.step = 0,
  85. this.stepDaily = 0,
  86. this.stepGame = 0,
  87. this.stepRate = 0,
  88. this.stepRateMax = 0});
  89. Sum.fromJson(Map<String, dynamic> json) {
  90. stepDayAvg = Converter.toDouble(json['step_day_avg']);
  91. distance = json['distance'];
  92. step = json['step'];
  93. stepDaily = json['step_daily'];
  94. stepGame = json['step_game'];
  95. stepJog = json['step_jog'];
  96. stepRate = Converter.toDouble(json['step_rate']);
  97. stepRateMax = Converter.toDouble(json['step_rate_max']);
  98. }
  99. Map<String, dynamic> toJson() {
  100. final Map<String, dynamic> data = new Map<String, dynamic>();
  101. data['step_day_avg'] = this.stepDayAvg;
  102. data['distance'] = this.distance;
  103. data['step'] = this.step;
  104. data['step_daily'] = this.stepDaily;
  105. data['step_game'] = this.stepGame;
  106. data['step_rate'] = this.stepRate;
  107. data['step_rate_max'] = this.stepRateMax;
  108. return data;
  109. }
  110. int get total{
  111. return stepDaily + stepGame + stepJog;
  112. }
  113. }