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:
John Mizerek 2026-01-01 16:37:18 -08:00
parent 80fdc80e3f
commit 5bfbf3dd27

View file

@ -1058,9 +1058,16 @@ class _ItemCustomizationSheetState extends State<_ItemCustomizationSheet> {
Widget _buildSelectionWidget(MenuItem item, MenuItem parent) {
final isSelected = _selectedItemIds.contains(item.itemId);
final siblings = widget.itemsByParent[parent.itemId] ?? [];
// Radio button if max selection is 1
if (parent.maxNumSelectionReq == 1) {
// Determine if this should behave as a radio button group:
// 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>(
value: item.itemId,
groupValue: _getSelectedInGroup(parent.itemId),
@ -1090,10 +1097,17 @@ class _ItemCustomizationSheetState extends State<_ItemCustomizationSheet> {
_validationError = null;
final isCurrentlySelected = _selectedItemIds.contains(item.itemId);
// For radio buttons (max = 1), deselect siblings and always select the clicked item
if (parent.maxNumSelectionReq == 1) {
final siblings = widget.itemsByParent[parent.itemId] ?? [];
// Determine if this should behave as a radio button group:
// 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));
// For radio buttons, deselect siblings and always select the clicked item
if (isRadioGroup) {
for (final sibling in siblings) {
_selectedItemIds.remove(sibling.itemId);
_deselectDescendants(sibling.itemId);