import 'dart:convert'; import 'dart:io'; import 'dart:convert' as convert; import 'package:sport/pages/run/location.dart'; import 'package:sport/services/Converter.dart'; class JogDetail { int? id; int? userId; String? type; int? recordId; int? consume; int? duration; int? step; int? distance; int? crouch; int? jump; double? stepRate; String? createdAt; int? jumpRate; int? crouchRate; String? begin; String? end; String? track; List? kmDurationInfo; String? stepInfo; String? altitudeInfo; int? kmDurationBest; int? activeDay; String? trackThumb; double? met; List? points; JogDetail( {this.id, this.userId, this.type, this.recordId, this.consume, this.duration, this.step, this.distance, this.crouch, this.jump, this.stepRate, this.createdAt, this.jumpRate, this.crouchRate, this.begin, this.end, this.track, this.kmDurationInfo, this.stepInfo, this.altitudeInfo, this.kmDurationBest, this.activeDay}); JogDetail.fromJson(Map json) { id = json['id']; userId = json['user_id']; type = json['type']; recordId = json['record_id']; consume = json['consume']; duration = json['duration']; step = json['step']; distance = json['distance']; crouch = json['crouch']; jump = json['jump']; stepRate = Converter.toDouble(json['step_rate']); createdAt = json['created_at']; jumpRate = json['jump_rate']; crouchRate = json['crouch_rate']; begin = json['begin']; end = json['end']; track = json['track']; if (track?.isNotEmpty == true) { points = []; String _track; if (track!.startsWith("[{")) { _track = track!; } else if (track!.startsWith("[")) { List array = convert.json.decode(track!).cast(); var compressed = gzip.decode(array); var original = utf8.decode(compressed); _track = original; }else { var trackInfo = base64.decode(track!); var compressed = gzip.decode(trackInfo); var original = utf8.decode(compressed); _track = original; } var list = convert.json.decode(_track); list.forEach((v) { points!.add(Location.fromJson(v)); }); } kmDurationInfo = json['km_duration_info'] != null ? json['km_duration_info'].cast() : []; stepInfo = json['step_info']; altitudeInfo = json['altitude_info']; kmDurationBest = json['km_duration_best']; activeDay = json['active_day']; trackThumb = json['track_thumb']; met = Converter.toDouble(json['met']); } Map toJson() { final Map data = new Map(); data['id'] = this.id; data['user_id'] = this.userId; data['type'] = this.type; data['record_id'] = this.recordId; data['consume'] = this.consume; data['duration'] = this.duration; data['step'] = this.step; data['distance'] = this.distance; data['crouch'] = this.crouch; data['jump'] = this.jump; data['step_rate'] = this.stepRate; data['created_at'] = this.createdAt; data['jump_rate'] = this.jumpRate; data['crouch_rate'] = this.crouchRate; data['begin'] = this.begin; data['end'] = this.end; data['track'] = this.track; data['km_duration_info'] = this.kmDurationInfo; data['step_info'] = this.stepInfo; data['altitude_info'] = this.altitudeInfo; data['km_duration_best'] = this.kmDurationBest; return data; } }