import 'package:sport/services/Converter.dart'; class User { int? id; int? userId; int? gameId; num? score; int? provinceId; int? cityId; int? districtId; String? finishAt; int? duration; int? consume; int? up; int? upNew; String? rateBegin; String? rateEnd; String? userName; String? userAvatar; int? userLevel; String? userLevelLogo; int? userGender; int? userAge; int? position; int? sportDay; List? achievements; User( {this.id, this.userId, this.gameId, this.score, this.provinceId, this.cityId, this.districtId, this.finishAt, this.duration, this.consume, this.up, this.upNew, this.rateBegin, this.rateEnd, this.userName, this.userAvatar, this.userLevel, this.userLevelLogo, this.userGender, this.userAge, this.position, this.achievements}); User.fromJson(Map json) { id = json['id']; userId = json['user_id']; gameId = json['game_id']; score = json['score']; provinceId = json['province_id']; cityId = json['city_id']; districtId = json['district_id']; finishAt = json['finish_at']; duration = json['duration']; consume = json['consume']; up = json['up']; upNew = Converter.toInt(json['up_new']); rateBegin = json['rate_begin']; rateEnd = json['rate_end']; userName = json['user_name']; userAvatar = json['user_avatar']; userLevel = json['user_level']; userLevelLogo = json['user_level_logo']; userGender = json['user_gender']; userAge = json['user_age']; position = json['position']; sportDay = json['sport_day'] ?? 0; if (json['achievements'] != null) { achievements = []; json['achievements'].forEach((v) { achievements!.add(new Achievement.fromJson(v)); }); } } Map toJsonSimple() { final Map data = new Map(); data['id'] = this.userId; data['nickname'] = this.userName; data['gender'] = this.userGender; data['avatar'] = this.userAvatar?.replaceAll("http://", "https://"); return data; } Map toJson() { final Map data = new Map(); data['id'] = this.id; data['user_id'] = this.userId; data['game_id'] = this.gameId; data['score'] = this.score; data['province_id'] = this.provinceId; data['city_id'] = this.cityId; data['district_id'] = this.districtId; data['finish_at'] = this.finishAt; data['duration'] = this.duration; data['consume'] = this.consume; data['up'] = this.up; data['up_new'] = this.upNew; data['rate_begin'] = this.rateBegin; data['rate_end'] = this.rateEnd; data['user_name'] = this.userName; data['user_avatar'] = this.userAvatar; data['user_level'] = this.userLevel; data['user_level_logo'] = this.userLevelLogo; data['user_gender'] = this.userGender; data['user_age'] = this.userAge; data['position'] = this.position; data['sport_day'] = this.sportDay; if (this.achievements != null) { data['achievements'] = this.achievements!.map((v) => v.toJson()).toList(); } return data; } } class Achievement { int? id; int? seriesId; String? logo; String? name; int? rewardExp; int? rewardScore; int conditionCount = 0; int conditionProgress = 0; int? userId; String? createdAt; String? conditionDetail; String? conditionMeasure; int? userCount; int? seriesCount; String? seriesName; // int? conditionCount; // int? conditionProgress; Achievement({ this.id, this.seriesId, this.logo, this.name, this.rewardExp, this.rewardScore, this.conditionCount = 0, this.conditionProgress = 0, this.createdAt, this.conditionDetail, this.conditionMeasure, this.userCount, this.seriesCount, this.seriesName, // this.conditionCount, // this.conditionProgress, }); Achievement.fromJson(Map json) { id = json['id']; userId = json['user_id']; seriesId = json['series_id']; logo = json['logo']; name = json['name']; rewardExp = json['reward_exp']; rewardScore = json['reward_score']; conditionCount = json['condition_count'] ?? 0; conditionProgress = json['condition_progress'] ?? 0; createdAt = json['created_at'] == null ? "" : json['created_at']; conditionDetail = json['condition_detail']; conditionMeasure = json['condition_measure']; userCount = json['user_count']; seriesCount = json['series_count']; seriesName = json['series_name']; // conditionProgress = json['condition_progress']; // conditionCount = json['condition_count']; } Map toJson() { final Map data = new Map(); data['id'] = this.id; data['user_id'] = this.userId; data['series_id'] = this.seriesId; data['logo'] = this.logo; data['name'] = this.name; data['reward_exp'] = this.rewardExp; data['reward_score'] = this.rewardScore; data['condition_count'] = this.conditionCount; data['condition_progress'] = this.conditionProgress; data['created_at'] = this.createdAt; data['condition_detail'] = this.conditionDetail; data['condition_measure'] = this.conditionMeasure; data['user_count'] = this.userCount; data['series_count'] = this.seriesCount; data['series_name'] = this.seriesName; // data['condition_progress'] = this.conditionProgress; // data['condition_count'] = this.conditionCount; return data; } } //class Achievement { // int? id; // String? name; // String? logo; // int? conditionSportDuration; // int? sort; // int? seriesId; // int? rewardScore; // // Achievement( // {this.id, // this.name, // this.logo, // this.conditionSportDuration, // this.sort, // this.seriesId, // this.rewardScore}); // // Achievement.fromJson(Map json) { // id = json['id']; // name = json['name']; // logo = json['logo']; // conditionSportDuration = json['condition_sport_duration'] == null ? json['condition_duration'] : json['condition_sport_duration']; // sort = json['sort']; // seriesId = json['series_id']; // rewardScore = json['reward_score']; // } // // Map toJson() { // final Map data = new Map(); // data['id'] = this.id; // data['name'] = this.name; // data['logo'] = this.logo; // data['condition_sport_duration'] = this.conditionSportDuration; // data['sort'] = this.sort; // data['series_id'] = this.seriesId; // data['reward_score'] = this.rewardScore; // return data; // } //}