workouttest_util/lib/model/exercise_tree.dart
2023-02-12 22:42:51 +01:00

77 lines
1.7 KiB
Dart

class ExerciseTree {
/// treeId
late int treeId;
/// parentId
late int parentId;
/// name
late String name;
/// imageUrl
late String imageUrl;
/// active
late bool active;
/// nameTranslation
late String nameTranslation;
/// sort
int? sort;
String? internalName;
String? description;
String? descriptionTranslation;
ExerciseTree();
ExerciseTree.fromJson(Map json) {
treeId = json['treeId'];
name = json['name'];
parentId = 0;
imageUrl = json['imageUrl'];
active = json['active'];
nameTranslation = json['translations'] != null && (json['translations']).length > 0 ? json['translations'][0]['name'] : name;
descriptionTranslation =
json['translations'] != null && (json['translations']).length > 0 && json['translations'][0]['description'] != null
? json['translations'][0]['description']
: description;
sort = 99;
internalName = json['internalName'];
}
Map<String, dynamic> toJson() {
return {
"treeId": treeId,
"parentId": parentId,
"name": name,
"description": description,
"imageUrl": imageUrl,
"active": active.toString(),
"nameTranslation": nameTranslation,
"descriptionTranslation": descriptionTranslation,
"sort": sort,
};
}
@override
String toString() => toJson().toString();
ExerciseTree copy(int parentId) {
ExerciseTree newTree = ExerciseTree();
newTree.treeId = treeId;
newTree.name = name;
newTree.imageUrl = imageUrl;
newTree.nameTranslation = nameTranslation;
if (parentId != -1) {
newTree.parentId = parentId;
}
newTree.active = active;
newTree.sort = sort ?? 99;
return newTree;
}
}