form_input 0.1.1 copy "form_input: ^0.1.1" to clipboard
form_input: ^0.1.1 copied to clipboard

A form input representation class.

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;
  }
}
1
likes
120
points
47
downloads

Publisher

unverified uploader

Weekly Downloads

A form input representation class.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

equatable, flutter

More

Packages that depend on form_input