updateAsyncRadioItem<T> method
Updates the label of an existing radio button item in an async radio group field by its value.
fieldName: The name of the async radio group field.value: The value to search for and update.label: The new label for the existing radio button item.
If the item doesn't exist, this method does nothing.
Implementation
void updateAsyncRadioItem<T>(
String fieldName, {
required T value,
required String label,
}) {
final field = state.asyncRadioGroup<T>(fieldName);
final cached = List<RadioButtonFieldState<T>>.from(field.cachedItems ?? []);
final index = cached.indexWhere((item) => item.value == value);
if (index == -1) return; // Value not found; exit
cached[index] = RadioButtonFieldState<T>(value, label: label);
state.fields[fieldName] = field.copyWith(
cachedItems: cached,
items: Future.value(cached),
);
state = state.copyWith(fields: Map.from(state.fields));
}