Field.builder constructor

Field.builder(
  1. String key, {
  2. required NyFieldBuilder builder,
  3. String? label,
  4. dynamic value,
  5. FormValidator? validator,
  6. bool autofocus = false,
  7. String? dummyData,
  8. Widget? header,
  9. Widget? footer,
  10. TextStyle? titleStyle,
  11. bool? hidden = false,
  12. bool? readOnly,
  13. FieldStyle? style,
  14. dynamic onChanged(
    1. dynamic value
    )?,
})

Field.builder is a constructor that lets developers create custom form fields inline using a builder function.

The builder receives the BuildContext, an onChanged callback to report value changes to the form, and the currentValue of the field.

Example:

Field.builder(
  'favorite_color',
  builder: (context, onChanged, value) {
    return ColorPicker(
      selected: value,
      onColorChanged: (color) => onChanged(color),
    );
  },
  value: Colors.blue,
  validator: FormValidator().notEmpty(),
)

Implementation

Field.builder(
  this.key, {
  required NyFieldBuilder builder,
  this.label,
  dynamic value,
  this.validator,
  this.autofocus = false,
  this.dummyData,
  this.header,
  this.footer,
  this.titleStyle,
  this.hidden = false,
  this.readOnly,
  FieldStyle? style,
  Function(dynamic value)? onChanged,
}) : _value = value,
     this.style = style {
  setOnChanged(onChanged);
  widget = NyFormBuilder.fromField(this, builder: builder);
}