controllerFor method

  1. @override
TextEditingController controllerFor(
  1. String fieldId
)
override

Implementation

@override
TextEditingController controllerFor(String fieldId) {
  if (!state.controllerMap.containsKey(fieldId)) {
    final List<String> oldKeys = state.data.keys.toList();
    dynamic fieldValue;
    if (oldKeys.isNotEmpty) {
      for (final String key in oldKeys) {
        final dynamic oldFieldValue = state.data[key];
        if (oldFieldValue != null) {
          fieldValue = oldFieldValue;
          break;
        }
      }
      for (final String key in oldKeys) {
        state.data.remove(key);
      }
    }
    final String text = fieldValue == null ? '' : fieldValue.toString();
    emit(state.copyWith(
      controllerMap: {
        ...state.controllerMap,
        fieldId: TextEditingController(text: text),
      },
    ));
  }
  return state.controllerMap[fieldId]!;
}