import 'dart:ui'; import 'package:workouttest_util/util/app_language.dart'; class ExercisePlanTemplate { late int? exercisePlanTemplateId; late String name; late String description; late String templateType; late String nameTranslation; late String descriptionTranslation; List exerciseTypes = []; ExercisePlanTemplate.fromJson(Map json) { this.exercisePlanTemplateId = json['exercisePlanId']; this.name = json['name']; this.description = json['description']; this.templateType = json['templateType']; if (json['translations'].length > 0) { this.nameTranslation = AppLanguage().appLocal == Locale('hu') ? json['translations'][0]['name'] : json['name']; this.descriptionTranslation = AppLanguage().appLocal == Locale('hu') ? json['translations'][0]['description'] : json['description']; } if (json['details'] != null && (json['details']).length > 0) { final List details = json['details']; details.sort((a, b) { if (a['sort'] == null || b['sort'] == null) { return a['exercisePlanTemplateDetailId'] < b['exercisePlanTemplateDetailId'] ? -1 : 1; } else { return a['sort'] < b['sort'] ? -1 : 1; } }); details.forEach((element) { exerciseTypes.add(element['exerciseTypeId']); }); } } Map toJson() { return { "exercisePlanTemplateId": exercisePlanTemplateId, "name": name, "description": "description", "templateType": templateType, "nameTranslation": nameTranslation, "descriptionTranslation": descriptionTranslation, "exerciseTypes": exerciseTypes.toString() }; } }