insertAsyncRadioItem<T> method

void insertAsyncRadioItem<T>(
  1. String fieldName, {
  2. required T value,
  3. required String label,
  4. int index = 0,
})

Inserts a new radio button item into the cached items of an async radio group field.

  • fieldName: The name of the async radio group field to update.
  • value: The value of the new radio button item.
  • label: The label for the new radio button item.
  • index: The position in the list where the new item should be inserted (default is 0).

Implementation

void insertAsyncRadioItem<T>(
  String fieldName, {
  required T value,
  required String label,
  int index = 0,
}) {
  final field = state.asyncRadioGroup<T>(fieldName);
  final cached = List<RadioButtonFieldState<T>>.from(field.cachedItems ?? []);
  cached.insert(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));
}