Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.

jezsung/form_input

Repository files navigation

Introduction

A simple form input representation helper class highly inspired by the formz package.

Examples

class EmailInput extends FormInput<String, Exception> {
  const EmailInput.pure([String value = '']) : super.pure(value);
  const EmailInput.dirty(String value) : super.dirty(value);
  // 'status' will be invalid, the validate function will be ignored.
  const EmailInput.invalid(String value, Exception e) : super.invalid(value, e);

  @override
  String sanitize(String value) {
    // 'rawValue' will be the value before the sanitize function called.
    // 'value' will be the value after the sanitize function called.
    return value.trim();
  }

  @override
  Exception? validate(String value) {
    if (value.isEmpty) {
      // Return Exception in case the validation fails.
      return FormatException('The email is empty.', value);
    }
    // Return null if the value is valid.
    return null;
  }
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages