FormSignal<T> class

Form field signal with validation support.

FormSignal manages form field state with built-in validation, dirty/touched tracking, and error messages.

Example:

class LoginController extends NeuronController {
  late final email = FormSignal<String>(
    '',
    validators: [
      Validators.required('Email is required'),
      Validators.email('Invalid email format'),
    ],
  ).bind(this);

  late final password = FormSignal<String>(
    '',
    validators: [
      Validators.required('Password is required'),
      Validators.minLength(6, 'Password must be at least 6 characters'),
    ],
  ).bind(this);

  bool get canSubmit => email.isValid && password.isValid;
}
Inheritance

Constructors

FormSignal(T initialValue, {List<Validator<T>> validators = const [], String? debugLabel, bool equals(NeuronFormState<T> a, NeuronFormState<T> b)?, NeuronFormState<T> guard(NeuronFormState<T> current, NeuronFormState<T> next)?, VoidCallback? onListen, VoidCallback? onCancel})

Properties

debugLabel String?
final
equals bool Function(NeuronFormState<T> a, NeuronFormState<T> b)?
Custom equality function to determine if value has changed.
finalinherited
error String?
Current error message.
no setter
guard NeuronFormState<T> Function(NeuronFormState<T> current, NeuronFormState<T> next)?
Value guard/transformer called before setting a new value.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether this atom has any listeners.
no setterinherited
initialValue NeuronFormState<T>
The initial value of the atom.
no setterinherited
isDirty bool
Whether the field has been modified.
no setter
isDisposed bool
Whether this atom has been disposed.
no setterinherited
isInvalid bool
Whether the field is invalid.
no setter
isPristine bool
Whether the field is pristine (not modified).
no setter
isTouched bool
Whether the field has been touched.
no setter
isUntouched bool
Whether the field is untouched.
no setter
isValid bool
Whether the field is valid.
no setter
onCancel VoidCallback?
Callback invoked when the last listener unsubscribes.
finalinherited
onListen VoidCallback?
Callback invoked when the first listener subscribes.
finalinherited
previousValue NeuronFormState<T>?
The previous value of the atom (before the last change).
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
val → T
Current value.
no setter
validators List<Validator<T>>
final
value NeuronFormState<T>
The current value of the atom.
getter/setter pairinherited

Methods

addListener(VoidCallback listener) → void
Adds a listener to be called when the value changes.
inherited
dispose() → void
Disposes the atom, removing all listeners.
inherited
emit(T val) → void
Emit a new value and validate.
markAsPristine() → void
Mark the field as pristine (reset dirty state).
markAsTouched() → void
Mark the field as touched (focused then blurred).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Manually notifies all listeners.
inherited
onActive() → void
Called when the first listener is added.
inherited
onInactive() → void
Called when the last listener is removed.
inherited
removeListener(VoidCallback listener) → void
Removes a previously added listener.
inherited
reset([T? initialValue]) → void
Reset to initial value.
override
select<R>(R selector(NeuronFormState<T> value)) NeuronAtom<R>
Creates a new atom that selects a part of this atom's value.
inherited
subscribe(VoidCallback listener) VoidCallback
Adds a listener and returns a callback that cancels the subscription when called.
inherited
toString() String
A string representation of this object.
inherited

Operators

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