exer_index.dart 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. import 'package:sport/bean/carousel.dart';
  2. import 'package:sport/bean/jog/detail.dart';
  3. import 'package:sport/bean/sport_index.dart' as sport;
  4. import 'package:sport/bean/user.dart';
  5. import 'package:sport/services/Converter.dart';
  6. //import 'package:sport/bean/user.dart';
  7. import 'game.dart' as game;
  8. class ExerIndex {
  9. Today? today;
  10. Target? target;
  11. List<Records>? records;
  12. List<game.GameInfoData>? games;
  13. List<Achievement>? newAchievements;
  14. List<NewRank>? newRank;
  15. int? jogUserCount;
  16. int? jogLastId;
  17. Sum? sum;
  18. JogLast? jogLast;
  19. bool showGuide = false;
  20. bool showExerData = false;
  21. String? fitSlogan;
  22. String? buyShoesUrl;
  23. List<Carousel>? carousel;
  24. List<Records>? recentRecords;
  25. ExerIndex({this.today, this.target, this.records, this.games, this.newAchievements, this.newRank});
  26. ExerIndex.fromJson(Map<String, dynamic> json) {
  27. jogUserCount = json['jog_user_count'];
  28. jogLastId = json['jog_last_id'];
  29. today = json['today'] != null ? new Today.fromJson(json['today']) : null;
  30. sum = json['sum'] != null ? new Sum.fromJson(json['sum']) : null;
  31. target = json['target'] != null ? new Target.fromJson(json['target']) : null;
  32. if (json['records'] != null) {
  33. records = [];
  34. json['records'].forEach((v) {
  35. records!.add(new Records.fromJson(v));
  36. });
  37. }
  38. if (json['recent_records'] != null) {
  39. recentRecords = [];
  40. json['recent_records'].forEach((v) {
  41. recentRecords!.add(new Records.fromJson(v));
  42. });
  43. }
  44. if (json['games'] != null) {
  45. games = [];
  46. json['games'].forEach((v) {
  47. games!.add(new game.GameInfoData.fromJson(v));
  48. });
  49. // games?.sort((a, b) => (a.h5??0) > 0 ? -1 : 1);
  50. }
  51. if (json['new_achievements'] != null) {
  52. newAchievements = [];
  53. json['new_achievements'].forEach((v) {
  54. newAchievements!.add(new Achievement.fromJson(v));
  55. });
  56. }
  57. if (json['new_rank'] != null) {
  58. newRank = [];
  59. json['new_rank'].forEach((v) {
  60. newRank!.add(new NewRank.fromJson(v));
  61. });
  62. }
  63. jogLast = json['jog_last'] != null ? new JogLast.fromJson(json['jog_last']) : null;
  64. showGuide = json['show_guide'] ?? false;
  65. showExerData = json['show_exer_data'] ?? false;
  66. fitSlogan = json['fit_slogan'];
  67. buyShoesUrl = json['buy_shoes_url'];
  68. if (json['carousel'] != null) {
  69. carousel = [];
  70. json['carousel'].forEach((v) {
  71. carousel!.add(new Carousel.fromMap(v));
  72. });
  73. }
  74. }
  75. Map<String, dynamic> toJson() {
  76. final Map<String, dynamic> data = new Map<String, dynamic>();
  77. if (this.today != null) {
  78. data['today'] = this.today!.toJson();
  79. }
  80. if (this.sum != null) {
  81. data['sum'] = this.sum!.toJson();
  82. }
  83. if (this.target != null) {
  84. data['target'] = this.target!.toJson();
  85. }
  86. if (this.records != null) {
  87. data['records'] = this.records!.map((v) => v.toJson()).toList();
  88. }
  89. if (this.games != null) {
  90. data['games'] = this.games!.map((v) => v.toJson()).toList();
  91. }
  92. if (this.newAchievements != null) {
  93. data['new_achievements'] = this.newAchievements!.map((v) => v.toJson()).toList();
  94. }
  95. if (this.newRank != null) {
  96. data['new_rank'] = this.newRank!.map((v) => v.toJson()).toList();
  97. }
  98. return data;
  99. }
  100. }
  101. class Today {
  102. int? id;
  103. int? userId;
  104. int? consume;
  105. int? consumeGame;
  106. int? consumeJog;
  107. int? duration;
  108. int? durationGame;
  109. int? durationJog;
  110. int? step;
  111. int? stepGame;
  112. int? stepJog;
  113. int? stepDaily;
  114. int? distance;
  115. int? distanceGame;
  116. int? distanceJog;
  117. int? distanceDaily;
  118. int? times;
  119. int? timesGame;
  120. int? timesJog;
  121. int? crouch;
  122. int? jump;
  123. String? createdAt;
  124. int? jumpRate;
  125. int? crouchRate;
  126. double? stepRate;
  127. double? stepRateGame;
  128. double? stepRateJog;
  129. int? kmDuration;
  130. double? met;
  131. Today(
  132. {this.id,
  133. this.userId,
  134. this.consume,
  135. this.consumeGame,
  136. this.consumeJog,
  137. this.duration,
  138. this.durationGame,
  139. this.durationJog,
  140. this.step,
  141. this.stepGame,
  142. this.stepJog,
  143. this.stepDaily,
  144. this.distance,
  145. this.distanceGame,
  146. this.distanceJog,
  147. this.distanceDaily,
  148. this.times,
  149. this.timesGame,
  150. this.timesJog,
  151. this.crouch,
  152. this.jump,
  153. this.createdAt,
  154. this.jumpRate,
  155. this.crouchRate,
  156. this.stepRate,
  157. this.stepRateGame,
  158. this.stepRateJog,
  159. this.kmDuration});
  160. Today.fromJson(Map<String, dynamic> json) {
  161. id = json['id'];
  162. userId = json['user_id'];
  163. consume = json['consume'] ?? 0;
  164. consumeGame = json['consume_game'];
  165. consumeJog = json['consume_jog'];
  166. duration = json['duration'] ?? 0;
  167. durationGame = json['duration_game'];
  168. durationJog = json['duration_jog'];
  169. step = json['step'];
  170. stepGame = json['step_game'];
  171. stepJog = json['step_jog'];
  172. stepDaily = json['step_daily'];
  173. distance = json['distance'];
  174. distanceGame = json['distance_game'];
  175. distanceJog = json['distance_jog'];
  176. distanceDaily = json['distance_daily'];
  177. times = json['times'];
  178. timesGame = json['times_game'];
  179. timesJog = json['times_jog'];
  180. crouch = json['crouch'];
  181. jump = json['jump'];
  182. createdAt = json['created_at'];
  183. jumpRate = json['jump_rate'];
  184. crouchRate = json['crouch_rate'];
  185. stepRate = Converter.toDouble(json['step_rate']);
  186. stepRateGame = Converter.toDouble(json['step_rate_game']);
  187. stepRateJog = Converter.toDouble(json['step_rate_jog']);
  188. kmDuration = json['km_duration'];
  189. met = Converter.toDouble(json['met']);
  190. }
  191. Map<String, dynamic> toJson() {
  192. final Map<String, dynamic> data = new Map<String, dynamic>();
  193. data['id'] = this.id;
  194. data['user_id'] = this.userId;
  195. data['consume'] = this.consume;
  196. data['consume_game'] = this.consumeGame;
  197. data['consume_jog'] = this.consumeJog;
  198. data['duration'] = this.duration;
  199. data['duration_game'] = this.durationGame;
  200. data['duration_jog'] = this.durationJog;
  201. data['step'] = this.step;
  202. data['step_game'] = this.stepGame;
  203. data['step_jog'] = this.stepJog;
  204. data['step_daily'] = this.stepDaily;
  205. data['distance'] = this.distance;
  206. data['distance_game'] = this.distanceGame;
  207. data['distance_jog'] = this.distanceJog;
  208. data['distance_daily'] = this.distanceDaily;
  209. data['times'] = this.times;
  210. data['times_game'] = this.timesGame;
  211. data['times_jog'] = this.timesJog;
  212. data['crouch'] = this.crouch;
  213. data['jump'] = this.jump;
  214. data['created_at'] = this.createdAt;
  215. data['jump_rate'] = this.jumpRate;
  216. data['crouch_rate'] = this.crouchRate;
  217. data['step_rate'] = this.stepRate;
  218. data['step_rate_game'] = this.stepRateGame;
  219. data['step_rate_jog'] = this.stepRateJog;
  220. data['km_duration'] = this.kmDuration;
  221. return data;
  222. }
  223. double? get strength => sport.strengthToValue((consumeGame ?? 0) + (consumeJog ?? 0), duration);
  224. double? get metValue => met;
  225. String? strengthLabel() {
  226. return sport.strengthMetToLabel(met ?? 0);
  227. }
  228. int? value(String? type) => type == "consume" ? consume : ((duration ?? 0) / 60).round();
  229. int? get minute => (duration ?? 0) ~/ 60;
  230. String stepToStr() {
  231. int num = this.step ?? 0;
  232. return (num > 100000) ? "${(num / 10000.0).toStringAsFixed(1)}万" : "$num";
  233. }
  234. }
  235. class Target {
  236. int? id;
  237. int? userId;
  238. int? consume;
  239. int? duration;
  240. String? type;
  241. int? durationMinute;
  242. int? monthFinish;
  243. int? get valueTarget => type == "duration" ? (duration ?? 0) ~/ 60 : consume;
  244. String? get label => type == "duration" ? "分钟" : "大卡";
  245. double? progress(Today? today) {
  246. if (today == null) return 0;
  247. if (type == "consume") {
  248. return today.consume! / this.consume!;
  249. } else {
  250. return (today.duration ?? 0) / this.duration!;
  251. }
  252. }
  253. Target({this.id, this.userId, this.consume, this.duration, this.type, this.durationMinute, this.monthFinish});
  254. Target.fromJson(Map<String, dynamic> json) {
  255. id = json['id'];
  256. userId = json['user_id'];
  257. consume = json['consume'];
  258. duration = json['duration'];
  259. type = json['type'];
  260. durationMinute = json['duration_minute'];
  261. monthFinish = json['month_finish'];
  262. }
  263. Map<String, dynamic> toJson() {
  264. final Map<String, dynamic> data = new Map<String, dynamic>();
  265. data['id'] = this.id;
  266. data['user_id'] = this.userId;
  267. data['consume'] = this.consume;
  268. data['duration'] = this.duration;
  269. data['type'] = this.type;
  270. data['duration_minute'] = this.durationMinute;
  271. data['month_finish'] = this.monthFinish;
  272. return data;
  273. }
  274. }
  275. class Records {
  276. int? gameId;
  277. String? name;
  278. String? cover;
  279. int userCount = 0;
  280. int times = 0;
  281. int duration = 0;
  282. int? consume;
  283. Records({this.gameId, this.name, this.cover, this.userCount = 0, this.times = 0, this.duration = 0, this.consume});
  284. Records.fromJson(Map<String, dynamic> json) {
  285. gameId = json['game_id'];
  286. name = json['name'];
  287. cover = json['cover'];
  288. userCount = json['user_count'];
  289. times = json['times'];
  290. duration = json['duration'];
  291. consume = Converter.toInt(json['consume']);
  292. }
  293. Map<String, dynamic> toJson() {
  294. final Map<String, dynamic> data = new Map<String, dynamic>();
  295. data['game_id'] = this.gameId;
  296. data['name'] = this.name;
  297. data['cover'] = this.cover;
  298. data['user_count'] = this.userCount;
  299. data['times'] = this.times;
  300. data['duration'] = this.duration;
  301. data['consume'] = this.consume;
  302. return data;
  303. }
  304. }
  305. class NewRank {
  306. int? id;
  307. String? name;
  308. int? position;
  309. String? createdAt;
  310. NewRank({this.id, this.name, this.position, this.createdAt});
  311. NewRank.fromJson(Map<String, dynamic> json) {
  312. id = json['id'];
  313. name = json['name'];
  314. position = json['position'];
  315. createdAt = json['created_at'];
  316. }
  317. Map<String, dynamic> toJson() {
  318. final Map<String, dynamic> data = new Map<String, dynamic>();
  319. data['id'] = this.id;
  320. data['name'] = this.name;
  321. data['position'] = this.position;
  322. data['created_at'] = this.createdAt;
  323. return data;
  324. }
  325. }
  326. class Sum {
  327. int? id;
  328. int? userId;
  329. int? consume;
  330. int? consumeGame;
  331. int? consumeJog;
  332. int? consumeDaily;
  333. int? duration;
  334. int? durationGame;
  335. int? durationJog;
  336. int? step;
  337. int? stepGame;
  338. int? stepJog;
  339. int? stepDaily;
  340. int? distance;
  341. int? distanceGame;
  342. int? distanceJog;
  343. int? distanceDaily;
  344. int? times;
  345. int? timesGame;
  346. int? timesJog;
  347. int? crouch;
  348. int? jump;
  349. int? durationGameStep;
  350. int? durationJump;
  351. int? durationCrouch;
  352. int? durationStep;
  353. int? jumpRate;
  354. int? crouchRate;
  355. double? stepRate;
  356. double? stepRateGame;
  357. double? stepRateJog;
  358. Sum(
  359. {this.id,
  360. this.userId,
  361. this.consume,
  362. this.consumeGame,
  363. this.consumeJog,
  364. this.consumeDaily,
  365. this.duration,
  366. this.durationGame,
  367. this.durationJog,
  368. this.step,
  369. this.stepGame,
  370. this.stepJog,
  371. this.stepDaily,
  372. this.distance,
  373. this.distanceGame,
  374. this.distanceJog,
  375. this.distanceDaily,
  376. this.times,
  377. this.timesGame,
  378. this.timesJog,
  379. this.crouch,
  380. this.jump,
  381. this.durationGameStep,
  382. this.durationJump,
  383. this.durationCrouch,
  384. this.durationStep,
  385. this.jumpRate,
  386. this.crouchRate,
  387. this.stepRate,
  388. this.stepRateGame,
  389. this.stepRateJog});
  390. Sum.fromJson(Map<String, dynamic> json) {
  391. id = json['id'];
  392. userId = json['user_id'];
  393. consume = json['consume'];
  394. consumeGame = json['consume_game'];
  395. consumeJog = json['consume_jog'];
  396. consumeDaily = json['consume_daily'];
  397. duration = json['duration'];
  398. durationGame = json['duration_game'];
  399. durationJog = json['duration_jog'];
  400. step = json['step'];
  401. stepGame = json['step_game'];
  402. stepJog = json['step_jog'];
  403. stepDaily = json['step_daily'];
  404. distance = json['distance'];
  405. distanceGame = json['distance_game'];
  406. distanceJog = json['distance_jog'];
  407. distanceDaily = json['distance_daily'];
  408. times = json['times'];
  409. timesGame = json['times_game'];
  410. timesJog = json['times_jog'];
  411. crouch = json['crouch'];
  412. jump = json['jump'];
  413. durationGameStep = json['duration_game_step'];
  414. durationJump = json['duration_jump'];
  415. durationCrouch = json['duration_crouch'];
  416. durationStep = json['duration_step'];
  417. jumpRate = json['jump_rate'];
  418. crouchRate = json['crouch_rate'];
  419. stepRate = Converter.toDouble(json['step_rate']);
  420. stepRateGame = Converter.toDouble(json['step_rate_game']);
  421. stepRateJog = Converter.toDouble(json['step_rate_jog']);
  422. }
  423. Map<String, dynamic> toJson() {
  424. final Map<String, dynamic> data = new Map<String, dynamic>();
  425. data['id'] = this.id;
  426. data['user_id'] = this.userId;
  427. data['consume'] = this.consume;
  428. data['consume_game'] = this.consumeGame;
  429. data['consume_jog'] = this.consumeJog;
  430. data['consume_daily'] = this.consumeDaily;
  431. data['duration'] = this.duration;
  432. data['duration_game'] = this.durationGame;
  433. data['duration_jog'] = this.durationJog;
  434. data['step'] = this.step;
  435. data['step_game'] = this.stepGame;
  436. data['step_jog'] = this.stepJog;
  437. data['step_daily'] = this.stepDaily;
  438. data['distance'] = this.distance;
  439. data['distance_game'] = this.distanceGame;
  440. data['distance_jog'] = this.distanceJog;
  441. data['distance_daily'] = this.distanceDaily;
  442. data['times'] = this.times;
  443. data['times_game'] = this.timesGame;
  444. data['times_jog'] = this.timesJog;
  445. data['crouch'] = this.crouch;
  446. data['jump'] = this.jump;
  447. data['duration_game_step'] = this.durationGameStep;
  448. data['duration_jump'] = this.durationJump;
  449. data['duration_crouch'] = this.durationCrouch;
  450. data['duration_step'] = this.durationStep;
  451. data['jump_rate'] = this.jumpRate;
  452. data['crouch_rate'] = this.crouchRate;
  453. data['step_rate'] = this.stepRate;
  454. data['step_rate_game'] = this.stepRateGame;
  455. data['step_rate_jog'] = this.stepRateJog;
  456. return data;
  457. }
  458. }
  459. class JogLast {
  460. int? userId;
  461. String? type;
  462. int? recordId;
  463. String? createdAt;
  464. int? duration;
  465. double? distance;
  466. int? step;
  467. int? consume;
  468. double? stepRate;
  469. int? id;
  470. double? jumpRate;
  471. double? crouchRate;
  472. JogDetail? jogRecord;
  473. JogLast({this.userId, this.type, this.recordId, this.createdAt, this.duration, this.distance, this.step, this.consume, this.stepRate, this.id, this.jumpRate, this.crouchRate, this.jogRecord});
  474. JogLast.fromJson(Map<String, dynamic> json) {
  475. userId = json['user_id'];
  476. type = json['type'];
  477. recordId = json['record_id'];
  478. createdAt = json['created_at'];
  479. duration = json['duration'];
  480. distance = Converter.toDouble(json['distance']);
  481. step = Converter.toInt(json['step']);
  482. consume = Converter.toInt(json['consume']);
  483. stepRate = Converter.toDouble(json['step_rate']);
  484. id = json['id'];
  485. jumpRate = Converter.toDouble(json['jump_rate']);
  486. crouchRate = Converter.toDouble(json['crouch_rate']);
  487. jogRecord = json['jog_record'] != null ? new JogDetail.fromJson(json['jog_record']) : null;
  488. }
  489. Map<String, dynamic> toJson() {
  490. final Map<String, dynamic> data = new Map<String, dynamic>();
  491. data['user_id'] = this.userId;
  492. data['type'] = this.type;
  493. data['record_id'] = this.recordId;
  494. data['created_at'] = this.createdAt;
  495. data['duration'] = this.duration;
  496. data['distance'] = this.distance;
  497. data['step'] = this.step;
  498. data['consume'] = this.consume;
  499. data['step_rate'] = this.stepRate;
  500. data['id'] = this.id;
  501. data['jump_rate'] = this.jumpRate;
  502. data['crouch_rate'] = this.crouchRate;
  503. if (this.jogRecord != null) {
  504. data['jog_record'] = this.jogRecord!.toJson();
  505. }
  506. return data;
  507. }
  508. }