initRadioState method
void
initRadioState()
inherited
Implementation
void initRadioState() {
// Cache the group name when it's first set
if (_radioElement.name.isNotEmpty && _cachedGroupName == null) {
_cachedGroupName = _radioElement.name;
}
_subscription = streamController.stream.listen((message) {
setState(() {
for (var entry in message.entries) {
String groupName = _cachedGroupName ?? _radioElement.name;
if (entry.key == groupName) {
_updateGroupValues(entry.key, entry.value);
_currentGroupValue = entry.value; // Update instance cache
}
}
});
});
// Check if this radio is initially checked or has early checked state.
// Use element identity as key to avoid collisions between different groups with the same value.
String radioKey = _radioElement.hashCode.toString();
final bool? early = RadioElementState.getEarlyCheckedState(radioKey);
final bool isInitiallyChecked = _radioElement.hasAttribute('checked');
if (early != null && early != true) {
RadioElementState.clearEarlyCheckedState(radioKey);
}
if (early == true || isInitiallyChecked) {
String groupName = _cachedGroupName ?? _radioElement.selectionGroupName;
String selectionValue = _radioElement.selectionValue;
_updateGroupValues(groupName, selectionValue);
_currentGroupValue = selectionValue; // Cache at instance level
setState(() {});
if (early != null) RadioElementState.clearEarlyCheckedState(radioKey);
} else {
String groupName = _cachedGroupName ?? _radioElement.selectionGroupName;
if (_groupValues.containsKey(groupName)) {
setState(() {});
}
}
}