detail.dart 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import 'dart:convert';
  2. import 'dart:io';
  3. import 'dart:convert' as convert;
  4. import 'package:sport/pages/run/location.dart';
  5. import 'package:sport/services/Converter.dart';
  6. class JogDetail {
  7. int? id;
  8. int? userId;
  9. String? type;
  10. int? recordId;
  11. int? consume;
  12. int? duration;
  13. int? step;
  14. int? distance;
  15. int? crouch;
  16. int? jump;
  17. double? stepRate;
  18. String? createdAt;
  19. int? jumpRate;
  20. int? crouchRate;
  21. String? begin;
  22. String? end;
  23. String? track;
  24. List<int>? kmDurationInfo;
  25. String? stepInfo;
  26. String? altitudeInfo;
  27. int? kmDurationBest;
  28. int? activeDay;
  29. String? trackThumb;
  30. double? met;
  31. List<Location>? points;
  32. JogDetail(
  33. {this.id,
  34. this.userId,
  35. this.type,
  36. this.recordId,
  37. this.consume,
  38. this.duration,
  39. this.step,
  40. this.distance,
  41. this.crouch,
  42. this.jump,
  43. this.stepRate,
  44. this.createdAt,
  45. this.jumpRate,
  46. this.crouchRate,
  47. this.begin,
  48. this.end,
  49. this.track,
  50. this.kmDurationInfo,
  51. this.stepInfo,
  52. this.altitudeInfo,
  53. this.kmDurationBest,
  54. this.activeDay});
  55. JogDetail.fromJson(Map<String, dynamic> json) {
  56. id = json['id'];
  57. userId = json['user_id'];
  58. type = json['type'];
  59. recordId = json['record_id'];
  60. consume = json['consume'];
  61. duration = json['duration'];
  62. step = json['step'];
  63. distance = json['distance'];
  64. crouch = json['crouch'];
  65. jump = json['jump'];
  66. stepRate = Converter.toDouble(json['step_rate']);
  67. createdAt = json['created_at'];
  68. jumpRate = json['jump_rate'];
  69. crouchRate = json['crouch_rate'];
  70. begin = json['begin'];
  71. end = json['end'];
  72. track = json['track'];
  73. if (track?.isNotEmpty == true) {
  74. points = [];
  75. String _track;
  76. if (track!.startsWith("[{")) {
  77. _track = track!;
  78. } else if (track!.startsWith("[")) {
  79. List<int> array = convert.json.decode(track!).cast<int>();
  80. var compressed = gzip.decode(array);
  81. var original = utf8.decode(compressed);
  82. _track = original;
  83. }else {
  84. var trackInfo = base64.decode(track!);
  85. var compressed = gzip.decode(trackInfo);
  86. var original = utf8.decode(compressed);
  87. _track = original;
  88. }
  89. var list = convert.json.decode(_track);
  90. list.forEach((v) {
  91. points!.add(Location.fromJson(v));
  92. });
  93. }
  94. kmDurationInfo = json['km_duration_info'] != null ? json['km_duration_info'].cast<int>() : <int>[];
  95. stepInfo = json['step_info'];
  96. altitudeInfo = json['altitude_info'];
  97. kmDurationBest = json['km_duration_best'];
  98. activeDay = json['active_day'];
  99. trackThumb = json['track_thumb'];
  100. met = Converter.toDouble(json['met']);
  101. }
  102. Map<String, dynamic> toJson() {
  103. final Map<String, dynamic> data = new Map<String, dynamic>();
  104. data['id'] = this.id;
  105. data['user_id'] = this.userId;
  106. data['type'] = this.type;
  107. data['record_id'] = this.recordId;
  108. data['consume'] = this.consume;
  109. data['duration'] = this.duration;
  110. data['step'] = this.step;
  111. data['distance'] = this.distance;
  112. data['crouch'] = this.crouch;
  113. data['jump'] = this.jump;
  114. data['step_rate'] = this.stepRate;
  115. data['created_at'] = this.createdAt;
  116. data['jump_rate'] = this.jumpRate;
  117. data['crouch_rate'] = this.crouchRate;
  118. data['begin'] = this.begin;
  119. data['end'] = this.end;
  120. data['track'] = this.track;
  121. data['km_duration_info'] = this.kmDurationInfo;
  122. data['step_info'] = this.stepInfo;
  123. data['altitude_info'] = this.altitudeInfo;
  124. data['km_duration_best'] = this.kmDurationBest;
  125. data['met'] = this.met;
  126. return data;
  127. }
  128. }