InputFieldBloc<Value, ExtraData> constructor

InputFieldBloc<Value, ExtraData>({
  1. String? name,
  2. required Value initialValue,
  3. List<Validator<Value>>? validators,
  4. List<AsyncValidator<Value>>? asyncValidators,
  5. Duration asyncValidatorDebounceTime = const Duration(milliseconds: 500),
  6. Suggestions<Value>? suggestions,
  7. dynamic toJson(
    1. Value value
    )?,
  8. ExtraData? extraData,
})

InputFieldBloc<Value, ExtraData>

Properties:

  • name : It is the string that identifies the fieldBloc, it is available in FieldBlocState.name.
  • initialValue : The initial value of the field, by default is null.
  • validators : List of Validators. Each time the value will change, if the FormBloc that use this InputFieldBloc has set in the super constructor autoValidate = true, the value is passed to each validator, and if any validator returns a String error, it will be added to InputFieldBlocState.error. Else if autoValidate = false, the value will be checked only when you call validate which is called automatically when call FormBloc.submit.
  • asyncValidators : List of AsyncValidators. it is the same as validators but asynchronous. Very useful for server validation.
  • asyncValidatorDebounceTime : The debounce time when any asyncValidator must be called, by default is 500 milliseconds. Very useful for reduce the number of invocations of each `asyncValidator. For example, used for prevent limit in API calls.
  • suggestions : This need be a Suggestions and will be added to InputFieldBlocState.suggestions. It is used to suggest values, usually from an API, and any of those suggestions can be used to update the value using updateValue.
  • toJson Transform value in a JSON value. By default returns value. This method is called when you use FormBlocState.toJson
  • extraData : It is an object that you can use to add extra data, it will be available in the state FieldBlocState.extraData.

Implementation

InputFieldBloc({
  String? name,
  required Value initialValue,
  List<Validator<Value>>? validators,
  List<AsyncValidator<Value>>? asyncValidators,
  Duration asyncValidatorDebounceTime = const Duration(milliseconds: 500),
  Suggestions<Value>? suggestions,
  dynamic Function(Value value)? toJson,
  ExtraData? extraData,
}) : super(
        validators: validators,
        asyncValidators: asyncValidators,
        asyncValidatorDebounceTime: asyncValidatorDebounceTime,
        initialState: InputFieldBlocState(
          isValueChanged: false,
          initialValue: initialValue,
          updatedValue: initialValue,
          value: initialValue,
          error: FieldBlocUtils.getInitialStateError(
            validators: validators,
            value: initialValue,
          ),
          isDirty: false,
          suggestions: suggestions,
          isValidated: FieldBlocUtils.getInitialIsValidated(
            FieldBlocUtils.getInitialStateIsValidating(
              asyncValidators: asyncValidators,
              validators: validators,
              value: initialValue,
            ),
          ),
          isValidating: FieldBlocUtils.getInitialStateIsValidating(
            asyncValidators: asyncValidators,
            validators: validators,
            value: initialValue,
          ),
          name: FieldBlocUtils.generateName(name),
          toJson: toJson,
          extraData: extraData,
        ),
      );