getErrorText method

String? getErrorText(
  1. BlocXTextFieldOptions options
)

Returns the first bloc-driven error for this field.

Falls back to BlocXTextFieldOptions.errorText when the bloc has no error for widget.formKey.

Implementation

String? getErrorText(BlocXTextFieldOptions options) {
  final index = bloc.state.errors.keys.toList().indexWhere((key) => key == widget.formKey);

  if (index >= 0) {
    return bloc.state.errors.values.toList()[index].first;
  }

  return options.errorText;
}