diff --git a/lib/src/body_part_selector.dart b/lib/src/body_part_selector.dart index 207d793..557bf49 100644 --- a/lib/src/body_part_selector.dart +++ b/lib/src/body_part_selector.dart @@ -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, @@ -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; @@ -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, diff --git a/lib/src/body_part_selector_turnable.dart b/lib/src/body_part_selector_turnable.dart index d8c9c64..a8769a4 100644 --- a/lib/src/body_part_selector_turnable.dart +++ b/lib/src/body_part_selector_turnable.dart @@ -42,7 +42,6 @@ class BodyPartSelectorTurnable extends StatelessWidget { ), ), ), - labels: labelData, ); } } diff --git a/lib/src/model/body_parts.dart b/lib/src/model/body_parts.dart index c7c606a..66e3f43 100644 --- a/lib/src/model/body_parts.dart +++ b/lib/src/model/body_parts.dart @@ -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 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); } } diff --git a/pubspec.yaml b/pubspec.yaml index 4ce7830..24d0056 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: