Field<T> class

An immutable, reactive form field with built-in validation, dynamic label and hint inference, callable shorthand mutator, backend error support, and value-equality via Equatable.

Fluent Builder Usage:

final email = Field(
  labelText: 'Corporate email',
  value: '',
  hintText: 'e.g. alex@company.com',
  validators: Validators.required().email(),
);

// Shorthand callable update syntax:
final updated = email('user@company.com');
Mixed-in types

Constructors

Field({required T value, String? labelText, String? hintText, String? helperText, bool isDirty = false, List<Validator> validators = const [], String? customError})
const

Properties

customError → String?
final
error → String?
Returns customError if set (e.g. from backend), otherwise the first validator error.
no setter
hasError → bool
Whether the field has been touched (or has a custom error) AND has an error. Use this to decide when to show error text in the UI.
no setter
hashCode → int
The hash code for this object.
no setterinherited
helperText → String?
final
hintText → String?
final
isDirty → bool
final
isPure → bool
Opposite of isDirty — the field has not been touched and has no custom error.
no setter
isValid → bool
Whether all validators pass and no custom error is attached.
no setter
labelText → String?
final
props → List<Object?>
The list of properties that will be used to determine whether two instances are equal.
no setteroverride
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
stringify → bool?
If set to true, the toString method will be overridden to output this instance's props.
no setterinherited
validators → List<Validator>
final
value → T
final

Methods

call(T newValue) → Field<T>
Allows concise invocation state.email(value) instead of state.email.update(value).
copyWith({String? labelText, String? hintText, String? helperText, T? value, bool? isDirty, List<Validator>? validators, Object? customError = _sentinel}) → Field<T>
Creates a copy with optional overrides.
makeDirty() → Field<T>
Marks the field as dirty without changing its value.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reset() → Field<T>
Resets to pure state without changing its value.
setError(String? error) → Field<T>
Attaches a custom error (e.g., from server response) and marks field as dirty.
toString() → String
A string representation of this object.
inherited
update(T newValue) → Field<T>
Updates the value, marks the field as dirty, and clears any previous custom error.

Operators

operator ==(Object other) → bool
The equality operator.
inherited