Fix radio button inference for modifier groups
- Infer radio button behavior when group has exactly one default-checked item - Both visual (Radio widget) and behavior (_toggleSelection) now consistent - Fixes issue where selecting different option kept both default and selected 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
80fdc80e3f
commit
5bfbf3dd27
1 changed files with 19 additions and 5 deletions
|
|
@ -1058,9 +1058,16 @@ class _ItemCustomizationSheetState extends State<_ItemCustomizationSheet> {
|
||||||
|
|
||||||
Widget _buildSelectionWidget(MenuItem item, MenuItem parent) {
|
Widget _buildSelectionWidget(MenuItem item, MenuItem parent) {
|
||||||
final isSelected = _selectedItemIds.contains(item.itemId);
|
final isSelected = _selectedItemIds.contains(item.itemId);
|
||||||
|
final siblings = widget.itemsByParent[parent.itemId] ?? [];
|
||||||
|
|
||||||
// Radio button if max selection is 1
|
// Determine if this should behave as a radio button group:
|
||||||
if (parent.maxNumSelectionReq == 1) {
|
// 1. Explicit: maxNumSelectionReq == 1
|
||||||
|
// 2. Inferred: Group has exactly one default-checked item (implies single selection)
|
||||||
|
final isRadioGroup = parent.maxNumSelectionReq == 1 ||
|
||||||
|
(siblings.where((s) => s.isCheckedByDefault).length == 1 &&
|
||||||
|
siblings.every((s) => !s.requiresChildSelection));
|
||||||
|
|
||||||
|
if (isRadioGroup) {
|
||||||
return Radio<int>(
|
return Radio<int>(
|
||||||
value: item.itemId,
|
value: item.itemId,
|
||||||
groupValue: _getSelectedInGroup(parent.itemId),
|
groupValue: _getSelectedInGroup(parent.itemId),
|
||||||
|
|
@ -1090,10 +1097,17 @@ class _ItemCustomizationSheetState extends State<_ItemCustomizationSheet> {
|
||||||
_validationError = null;
|
_validationError = null;
|
||||||
|
|
||||||
final isCurrentlySelected = _selectedItemIds.contains(item.itemId);
|
final isCurrentlySelected = _selectedItemIds.contains(item.itemId);
|
||||||
|
final siblings = widget.itemsByParent[parent.itemId] ?? [];
|
||||||
|
|
||||||
// For radio buttons (max = 1), deselect siblings and always select the clicked item
|
// Determine if this should behave as a radio button group:
|
||||||
if (parent.maxNumSelectionReq == 1) {
|
// 1. Explicit: maxNumSelectionReq == 1
|
||||||
final siblings = widget.itemsByParent[parent.itemId] ?? [];
|
// 2. Inferred: Group has exactly one default-checked item (implies single selection)
|
||||||
|
final isRadioGroup = parent.maxNumSelectionReq == 1 ||
|
||||||
|
(siblings.where((s) => s.isCheckedByDefault).length == 1 &&
|
||||||
|
siblings.every((s) => !s.requiresChildSelection));
|
||||||
|
|
||||||
|
// For radio buttons, deselect siblings and always select the clicked item
|
||||||
|
if (isRadioGroup) {
|
||||||
for (final sibling in siblings) {
|
for (final sibling in siblings) {
|
||||||
_selectedItemIds.remove(sibling.itemId);
|
_selectedItemIds.remove(sibling.itemId);
|
||||||
_deselectDescendants(sibling.itemId);
|
_deselectDescendants(sibling.itemId);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue