EasyCustomFormField<T, C extends ValueNotifier> constructor

EasyCustomFormField<T, C extends ValueNotifier>({
  1. Key? key,
  2. required String name,
  3. C? controller,
  4. FocusNode? focusNode,
  5. T? initialValue,
  6. required CreateControllerCallback<C, T?> controllerBuilder,
  7. RecreateControllerCallback<C>? controllerRebuilder,
  8. ValueOfGetter<T?, C>? valueGet,
  9. ValueOfSetter<T?, C>? valueSet,
  10. required EasyFormCustomFieldBuilder<T, C> builder,
  11. ValueChanged<T>? onChanged,
  12. FormFieldSetter<T>? onSaved,
  13. EasyFormFieldValidator<T?>? validator,
  14. bool enabled = true,
  15. EasyAutovalidateMode autovalidateMode = EasyAutovalidateMode.disabled,
})

Creates a EasyCustomFormField that contains a custom field.

When a controller is specified, initialValue must be null (the default). If controller is null, then a Controller will be constructed automatically and its value will be initialized to initialValue or the empty value.

Implementation

EasyCustomFormField({
  Key? key,
  required String name,
  this.controller,
  FocusNode? focusNode,
  T? initialValue,
  required this.controllerBuilder,
  this.controllerRebuilder,
  this.valueGet,
  this.valueSet,
  required EasyFormCustomFieldBuilder<T, C> builder,
  ValueChanged<T>? onChanged,
  FormFieldSetter<T>? onSaved,
  EasyFormFieldValidator<T?>? validator,
  bool enabled = true,
  EasyAutovalidateMode autovalidateMode = EasyAutovalidateMode.disabled,
}) : super(
        key: key,
        name: name,
        focusNode: focusNode,
        initialValue: controller != null
            ? ((valueGet != null)
                ? valueGet.call(controller)
                : controller.value)
            : (initialValue ?? null),
        onSaved: onSaved,
        validator: validator,
        enabled: enabled,
        autovalidateMode: autovalidateMode,
        builder: (EasyFormFieldState<T?> field) {
          final _EasyCustomFormFieldState<T, C> state =
              field as _EasyCustomFormFieldState<T, C>;
          void onChangedHandler(T value) {
            if (onChanged != null) {
              onChanged(value);
            }
            field.didChange(value);
          }

          return builder(state, onChangedHandler);
        },
      );