51 lines
1.6 KiB
Dart
51 lines
1.6 KiB
Dart
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<int> exerciseTypes = [];
|
|
|
|
ExercisePlanTemplate.fromJson(Map json) {
|
|
exercisePlanTemplateId = json['exercisePlanId'];
|
|
name = json['name'];
|
|
description = json['description'];
|
|
templateType = json['templateType'];
|
|
if (json['translations'].length > 0) {
|
|
nameTranslation = AppLanguage().appLocal == const Locale('hu') ? json['translations'][0]['name'] : json['name'];
|
|
descriptionTranslation = AppLanguage().appLocal == const 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;
|
|
}
|
|
});
|
|
for (var element in details) {
|
|
exerciseTypes.add(element['exerciseTypeId']);
|
|
}
|
|
}
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
"exercisePlanTemplateId": exercisePlanTemplateId,
|
|
"name": name,
|
|
"description": "description",
|
|
"templateType": templateType,
|
|
"nameTranslation": nameTranslation,
|
|
"descriptionTranslation": descriptionTranslation,
|
|
"exerciseTypes": exerciseTypes.toString()
|
|
};
|
|
}
|
|
}
|