Field class
Represents a form field with configuration, validation, and state management capabilities.
Field is the core class that defines form field behavior, appearance, and data handling. It supports various field types including text, dropdowns, checkboxes, dates, and more. Each field can have validation rules, styling, and custom widgets attached.
Example usage:
final nameField = Field.text('name',
value: 'John Doe',
validator: FormValidator().notEmpty()
);
final countryField = Field.picker('country',
options: FormCollection.from({'US': 'United States'}),
value: 'US'
);
Constructors
- Field.capitalizeSentences(String key, {String? label, String? value, FormValidator? validator, bool autofocus = false, String? dummyData, Widget? header, TextStyle? titleStyle, bool? readOnly, FieldStyleTextField? style, dynamic onChanged(dynamic value)?})
- Field.capitalizeSentences is a constructor that helps in managing capitalizeSentences fields
- Field.capitalizeWords(String key, {String? label, String? value, FormValidator? validator, bool autofocus = false, String? dummyData, Widget? header, TextStyle? titleStyle, bool? readOnly, dynamic onChanged(dynamic value)?, FieldStyleTextField? style})
- Field.capitalizeWords is a constructor that helps in managing capitalizeWords fields
- Field.checkbox(String key, {String? label, dynamic value, FormValidator? validator, bool autofocus = false, String? dummyData, Widget? header, TextStyle? titleStyle, bool? readOnly, FieldStyleCheckbox? style, dynamic onChanged(dynamic value)?})
- Field.checkbox is a constructor that helps in managing textArea fields
- Field.chips(String key, {String? label, dynamic value, FormValidator? validator, bool autofocus = false, String? dummyData, Widget? header, TextStyle? titleStyle, bool? readOnly, required FormCollection options, dynamic onChanged(dynamic value)?, FieldStyleChip? style})
- Field.chips is a constructor that helps in managing chips fields
- Field.currency(String key, {String? label, required String currency, String? value, FormValidator? validator, bool autofocus = false, String? dummyData, Widget? header, TextStyle? titleStyle, bool? readOnly, dynamic onChanged(dynamic value)?, FieldStyleTextField? style})
- Field.currency is a constructor that helps in managing currency fields
- Field.custom(String key, {required NyFieldStatefulWidget child, String? label, dynamic value, FormValidator? validator, bool autofocus = false, String? dummyData, Widget? header, TextStyle? titleStyle, bool? readOnly, FieldStyle? style, dynamic onChanged(dynamic value)?})
- Field.capitalizeWords is a constructor that helps in managing capitalizeWords fields
- Field.date(String key, {String? label, dynamic value, FormValidator? validator, bool autofocus = false, String? dummyData, Widget? header, TextStyle? titleStyle, bool? readOnly, FieldStyleDateTimePicker? style, dynamic onChanged(dynamic value)?})
- Field.date is a constructor that helps in managing date fields
- Field.datetime(String key, {String? label, String? value, FormValidator? validator, bool autofocus = false, String? dummyData, Widget? header, TextStyle? titleStyle, bool? readOnly, FieldStyleDateTimePicker? style, dynamic onChanged(dynamic value)?})
- Field.datetime is a constructor that helps in managing datetime fields
- Field.email(String key, {String? label, String? value, FormValidator? validator, bool autofocus = false, String? dummyData, Widget? header, TextStyle? titleStyle, bool? readOnly, dynamic onChanged(dynamic value)?, FieldStyleTextField? style})
- Field.email is a constructor that helps in managing password fields
- Field.mask(String key, {String? label, dynamic value, FormValidator? validator, bool autofocus = false, String? dummyData, Widget? header, TextStyle? titleStyle, bool? readOnly, Widget? prefixIcon, bool clearable = false, Widget? clearIcon, required String? mask, String match = r'[\w\d]', bool? maskReturnValue = false, FieldStyleTextField? style, dynamic onChanged(dynamic value)?})
- Field.mask is a constructor that helps in managing mask fields
- Field.number(String key, {String? label, int? value, FormValidator? validator, bool autofocus = false, String? dummyData, Widget? header, TextStyle? titleStyle, bool? readOnly, bool decimal = false, dynamic onChanged(dynamic value)?, FieldStyleTextField? style})
- Field.number is a constructor that helps in managing number fields
- Field.password(String key, {String? label, String? value, FormValidator? validator, bool autofocus = false, String? dummyData, Widget? header, TextStyle? titleStyle, bool viewable = false, bool? readOnly, dynamic onChanged(dynamic value)?, FieldStyleTextField? style})
- Field.password is a constructor that helps in managing password fields
- Field.phoneNumber(String key, {String? label, String? value, FormValidator? validator, bool autofocus = false, String? dummyData, Widget? header, TextStyle? titleStyle, bool? readOnly, FieldStyleTextField? style, dynamic onChanged(dynamic value)?})
- Field.phoneNumber is a constructor that helps in managing phoneNumber fields
- Field.picker(String key, {String? label, dynamic value, FormValidator? validator, bool autofocus = false, String? dummyData, Widget? header, TextStyle? titleStyle, bool? readOnly, required FormCollection options, FieldStylePicker? style, dynamic onChanged(dynamic value)?})
- Field.picker is a constructor that helps in managing picker fields
- Field.radio(String key, {String? label, dynamic value, FormValidator? validator, bool autofocus = false, String? dummyData, Widget? header, bool? readOnly, required FormCollection options, FieldStyleRadio? style, dynamic onChanged(dynamic value)?})
- Field.radio is a constructor that helps in managing radio fields
- Field.rangeSlider(String key, {String? label, RangeValues? value, FormValidator? validator, bool autofocus = false, String? dummyData, Widget? header, TextStyle? titleStyle, bool? readOnly, dynamic onChanged(dynamic value)?, FieldStyleRangeSlider? style})
- Field.rangeSlider is a constructor that helps in managing range slider fields
- Field.slider(String key, {String? label, double? value, FormValidator? validator, bool autofocus = false, String? dummyData, Widget? header, TextStyle? titleStyle, bool? readOnly, dynamic onChanged(dynamic value)?, FieldStyleSlider? style})
- Field.slider is a constructor that helps in managing slider fields
- Field.switchBox(String key, {String? label, dynamic value, FormValidator? validator, bool autofocus = false, String? dummyData, Widget? header, TextStyle? titleStyle, bool? readOnly, FieldStyleSwitchBox? style, dynamic onChanged(dynamic value)?})
- Field.switchBox is a constructor that helps in managing switch fields
- Field.text(String key, {String? label, String? value, FormValidator? validator, bool autofocus = false, String? dummyData, Widget? header, TextStyle? titleStyle, bool? readOnly, FieldStyleTextField? style, dynamic onChanged(dynamic value)?})
- Field.text is a constructor that helps in managing text fields
- Field.textArea(String key, {String? label, String? value, FormValidator? validator, bool autofocus = false, String? dummyData, Widget? header, TextStyle? titleStyle, bool? readOnly, FieldStyleTextField? style, dynamic onChanged(dynamic value)?})
- Field.textArea is a constructor that helps in managing textArea fields
- Field.url(String key, {String? label, String? value, FormValidator? validator, bool autofocus = false, String? dummyData, Widget? header, TextStyle? titleStyle, bool? readOnly, dynamic onChanged(dynamic value)?, FieldStyleTextField? style})
- Field.url is a constructor that helps in managing url fields
- Field.widget({required Widget child})
- Field.widget is a constructor that helps in managing widget fields
Properties
- autofocus ↔ bool
-
Whether this field should automatically receive focus when the form loads.
getter/setter pair
- dummyData ↔ String?
-
Sample data used for development/testing purposes.
getter/setter pair
- field → Widget?
-
Get the cast of the field
no setter
-
Optional widget to display below the field input.
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- header ↔ Widget?
-
Optional widget to display above the field input.
getter/setter pair
-
Controls the visibility of this field in the form.
getter/setter pair
- key ↔ String
-
The unique identifier for this field within a form.
getter/setter pair
- label ↔ String?
-
Optional custom display label for this field.
getter/setter pair
- name → String
-
Returns the display name for this field.
no setter
- onChanged ↔ dynamic Function(dynamic value)?
-
Callback function invoked when the field value changes.
getter/setter pair
- readOnly ↔ bool?
-
Controls whether the field accepts user input.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- stateKey → String
-
Generates a unique state key for this field.
no setter
- style ↔ FieldStyle?
-
The visual styling configuration for this field.
getter/setter pair
- titleStyle ↔ TextStyle?
-
Custom text styling for the field title/label.
getter/setter pair
- updated ↔ StreamController?
-
Stream controller for field update notifications.
getter/setter pair
- validator ↔ FormValidator?
-
Validation rules applied to this field.
getter/setter pair
- value ↔ dynamic
-
Gets the current field value.
getter/setter pair
- widget ↔ Widget?
-
Custom widget to render instead of the default field widget.
getter/setter pair
Methods
-
clear(
) → void - Clear the value of the field
-
hide(
) → void - Makes this field invisible in the form UI.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
restoreValue(
dynamic value) → void - Sets the field value without triggering UI widget updates. Used during hot reload to preserve values before the widget tree rebuilds.
-
setOnChanged(
dynamic onChanged(dynamic value)?) → void - Set the onChanged callback for the field
-
setStyle(
FieldStyle? style) → void - Updates the styling configuration for this field.
-
setUpdated(
StreamController? updated) → dynamic - Configures the stream controller for field updates.
-
setValue(
dynamic value) → void - Directly sets the field value and updates the UI widget.
-
show(
) → void - Makes this field visible in the form UI.
-
toString(
) → String -
A string representation of this object.
inherited
-
validate(
) → FormValidationResult? - Validates the current field value against configured validation rules.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited