Skip to main content

formux 2.1.3 copy "formux: ^2.1.3" to clipboard
formux: ^2.1.3 copied to clipboard

Form validator, input logging, dynamic error handling, integrable with running components and applicable for UI with flutter_formux

formux #

Form state and validation primitives for Dart and Flutter. This package contains no Flutter widgets. The companion package flutter_formux provides concrete inputs and UI components.

Install #

dart pub add formux

For Flutter widgets, also install flutter_formux:

flutter pub add flutter_formux

Quick example #

import 'package:formux/formux.dart';

class NameInput extends FormuxStringType {
  NameInput({super.value});

  @override
  void validator() => assertion(value.trim().isEmpty, 'Enter a name');

  @override
  void clear() {
    value = '';
    hideErrors();
  }
}

class ProfileForm extends Formux<ProfileForm> {
  ProfileForm({String name = ''}) : name = NameInput(value: name);

  final NameInput name;

  @override
  List<FormuxInput> get inputs => [name];

  @override
  ProfileForm copy() => ProfileForm(name: name.value);
}

void main() {
  final form = ProfileForm();
  print(form.passed); // false: the required name is empty.
  print(form.name.display); // false: initial errors are hidden.

  form.valid(); // Shows errors when validation fails.
  print(form.name.error); // Enter a name

  form.name.value = 'Ada'; // Revalidates this input.
  print(form.valid()); // true
}

This example copies the input value only. If a form is used as a CubitForm state, its copy implementation must deliberately handle the validation and display state its UI needs.

Documentation #

Licensed under Apache 2.0; see LICENSE.

1
likes
155
points
597
downloads

Documentation

Documentation
API reference

Publisher

verified publisherpipen.dev

Weekly Downloads

Form validator, input logging, dynamic error handling, integrable with running components and applicable for UI with flutter_formux

Homepage
Repository (GitHub)
View/report issues

Topics

#form #validations

License

MIT (license)

Dependencies

bloc, collection, email_validator

More

Packages that depend on formux