Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/src/body_part_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class BodyPartSelector extends StatelessWidget {
required this.bodyParts,
required this.onSelectionUpdated,
this.mirrored = false,
this.singleSelection = false,
this.selectedColor,
this.unselectedColor,
this.selectedOutlineColor,
Expand All @@ -25,6 +26,7 @@ class BodyPartSelector extends StatelessWidget {
final void Function(BodyParts bodyParts)? onSelectionUpdated;

final bool mirrored;
final bool singleSelection;

final Color? selectedColor;
final Color? unselectedColor;
Expand Down Expand Up @@ -61,9 +63,16 @@ class BodyPartSelector extends StatelessWidget {
painter: _BodyPainter(
root: drawable,
bodyParts: bodyParts,
onTap: (s) => onSelectionUpdated?.call(
bodyParts.withToggledId(s, mirror: mirrored),
),
// onTap: (s) =>
// onSelectionUpdated?.call(
// bodyParts.withToggledId(s, mirror: mirrored),
// ),
onTap: (s) {
// print('Selected ID: $bodyParts');
onSelectionUpdated?.call(
bodyParts.withToggledId(s, mirror: mirrored,singleSelection : singleSelection),
);
},
context: context,
selectedColor: selectedColor ?? colorScheme.inversePrimary,
unselectedColor: unselectedColor ?? colorScheme.inverseSurface,
Expand Down
1 change: 0 additions & 1 deletion lib/src/body_part_selector_turnable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class BodyPartSelectorTurnable extends StatelessWidget {
),
),
),
labels: labelData,
);
}
}
37 changes: 25 additions & 12 deletions lib/src/model/body_parts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,34 @@ class BodyParts with _$BodyParts {
/// If [id] doesn't represent a valid BodyPart, this returns an unchanged
/// Object. If [mirror] is true, and the BodyPart is one that exists on both
/// sides (e.g. Knee), the other side is toggled as well.
BodyParts withToggledId(String id, {bool mirror = false}) {
BodyParts withToggledId(String id,
{bool mirror = false, bool singleSelection = false}) {
final map = toJson();
if (!map.containsKey(id)) return this;
map[id] = !map[id];
if (mirror) {
if (id.contains("left")) {
final mirroredId =
id.replaceAll("left", "right").replaceAll("Left", "Right");
map[mirroredId] = map[id];
} else if (id.contains("right")) {
final mirroredId =
id.replaceAll("right", "left").replaceAll("Right", "Left");
map[mirroredId] = map[id];

if (singleSelection) {
if (map[id] == true) {
Set<String> allKeys = map.keys.toSet();
allKeys.forEach((key) {
map[key] = true;
});
map[id] = !map[id];
}
} else {
if (!map.containsKey(id)) return this;
map[id] = !map[id];
if (mirror) {
if (id.contains("left")) {
final mirroredId =
id.replaceAll("left", "right").replaceAll("Left", "Right");
map[mirroredId] = map[id];
} else if (id.contains("right")) {
final mirroredId =
id.replaceAll("right", "left").replaceAll("Right", "Left");
map[mirroredId] = map[id];
}
}
}

return BodyParts.fromJson(map);
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies:
flutter_svg: ^1.1.0
touchable: ^1.0.2
freezed_annotation: ^2.0.3
rotation_stage: ^0.0.3
rotation_stage: ^0.3.0

dev_dependencies:
flutter_test:
Expand Down