Skip to main content

API

MemberTypeDescription
FFormFieldConstructorAbstract base class constructor initializing a field with an initial value of type T. Automatically performs validation via check() upon creation.
E? exceptionGetter & SetterThe exception associated with the field after validation. null if valid. Updates listeners when changed.
bool get isValidGetterIndicates whether the field's value is valid (true if valid).
bool get isInvalidGetterIndicates whether the field's value is invalid (true if invalid).
Future<bool> check()MethodValidates the field by running the validator and updates the exception state. Returns true if the field is valid after validation.
E? validator(T value)Abstract MethodAbstract method for custom validation logic. Should return an exception of type E if validation fails, otherwise null.

Details of Key Members​

  1. FFormField Constructor

    • Initializes the field with an initial value of type T.
    • Immediately calls the check() method to validate the initial value.

    Example:

    final field = MyFormField(initialValue);
  2. E? exception Getter & Setter

    • Getter: Retrieves the current validation exception.
    • Setter: Sets a new exception and notifies listeners if the exception changes.

    Example:

    if (field.exception != null) {
    print('Validation error: ${field.exception}');
    }
  3. bool get isValid

    • Indicates the validity of the field's value based on the exception.

    Example:

    if (field.isValid) {
    print('Field is valid');
    }
  4. bool get isInvalid

    • Returns true when the field is invalid (opposite of isValid).

    Example:

    if (field.isInvalid) {
    print('Field is invalid');
    }
  5. Future<bool> check()

    • Validates the field by calling the validator method.
    • Updates the exception state and notifies listeners.
    • Returns true if the field is valid after validation.

    Example:

    final isValid = await field.check();
    if (isValid) {
    print('Field is valid');
    } else {
    print('Field is invalid');
    }
  6. E? validator(T value)

    • Must be implemented in subclasses to provide custom validation logic.
    • Should return an exception of type E if validation fails, or null if the value is valid.

    Example:


    MyException? validator(MyValue value) {
    if (value.isValid()) {
    return null;
    } else {
    return MyException('Invalid value');
    }
    }