From a93398dd2f536e8fb4357786e33b64be5f50d4ab Mon Sep 17 00:00:00 2001 From: talharasool Date: Wed, 21 Feb 2024 21:31:01 +0500 Subject: [PATCH 1/3] Enable Single Selection Now user can select the single body organ --- lib/src/body_part_selector.dart | 15 ++++++++++--- lib/src/model/body_parts.dart | 37 ++++++++++++++++++++++----------- 2 files changed, 37 insertions(+), 15 deletions(-) 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/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); } } From af9146410b949b2fc0cb4a3f05df37c04a0a8069 Mon Sep 17 00:00:00 2001 From: Aitzaz Nasir <135987660+aitzaz-dev@users.noreply.github.com> Date: Wed, 9 Oct 2024 22:52:32 +0500 Subject: [PATCH 2/3] Update pubspec.yaml --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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: From 5ff5ccb19050db2d8a3ffbde17960f76d4949afd Mon Sep 17 00:00:00 2001 From: Aitzaz Nasir <135987660+aitzaz-dev@users.noreply.github.com> Date: Fri, 11 Oct 2024 23:05:29 +0500 Subject: [PATCH 3/3] Update body_part_selector_turnable.dart --- lib/src/body_part_selector_turnable.dart | 1 - 1 file changed, 1 deletion(-) 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, ); } }