Eine Sammlung von Formularfeld-Validatoren, die über die Zusammensetzung ausgewählt und in verschiedenen Kombinationen gruppiert werden können – Dekorierermuster.
Aus öffentlichen Paketdaten erstellte Orientierung.
Formdator ist ein Dart-Paket, das eine flexible Sammlung von Formularfeld-Validatoren bietet, die mithilfe des Dekorationsmusters zusammengesetzt werden können. Es ermöglicht Entwicklern, mehrere Validierungsregeln nahtlos zu kombinieren und so wiederverwendbare und modulare Validierungslogik über Formulare hinweg zu erstellen. Ideal für Anwendungen, die dynamische oder komplexe Eingabeverifizierung erfordern, unterstützt es verschiedene Plattformen wie Mobilgeräte, Web und Desktop. Das Paket betont sauberen, komponierbaren Code und integriert sich problemlos in das Formular-Ökosystem von Flutter.
Anwendungsfälle
Dynamische Formularvalidierung
Komplexe Eingaberegelungen
Wiederverwendbare Validierungs-Komponenten
Plattformübergreifende Formulare
Benutzerdefinierte Validierungsketten
Echtzeit-Rückmeldung
Hauptmerkmale
zusammensetzbare Validatoren
Decorator-Muster-Implementierung
Platform-agnostic
Einfache Integration mit Flutter-Formularen
Modulare Gestaltung
erweiterbare Validierungslogik
Geeignet für
Entwickler, die komplexe Formulare erstellen
Teams, die wartbaren Validierungscode benötigen
Apps, die mehrere Regeln zur Validierung erfordern
Flutter-Projekte mit Cross-Platform-Anforderungen
Projekte, die auf Code-Wiederverwendbarkeit abzielen
Formdator is a fully object-oriented package for validating Flutter form fields.
Its main benefits, compared to all other similar packages, include:
Dependency-free: there is only pure Dart code.
Object-oriented mindset: the elements for validation are immutable
objects that can be combined in various configurations.
Classes with short — yet meaningful — names like Req for required fields;
ReqEmail for non-empty, well-formed emails; Len for length constraints;
Int for integer-only values; and so on.
Easy-to-compose validators: e.g., the command Trim(Email()) produces a
validator that trims an email value before validating it.
Multiple validation at once: you can apply multiple validation rules at once
by using the Pair or Rules classes.
Built-in set of compound validators: e.g., to validate an email and limit its
length to a maximum of 50 characters, simply use an instance of
Email.len(50) — write less; do more!
For easier integration with Flutter form fields, every validator implements the
call() method. As a result, any validator object can be called as a function —
Callable Classes.
Getting Started
The following code snippet demonstrates how you can easily group the Rules,
Req, Len and Email classes together to create a kind of
'email-max-50-characters' constraint.
@overrideWidgetbuild(BuildContext context) {
returnTextFormField(
validator: Rules<String>([ // The "Rules" class performs multiple validations at once.Req(blank: 'Please enter the email'), // "blank" is the error message in case of field left blank.Len.max(50, long: 'Email length cannot exceed 50 characters'), // "long" is the error message if an input value is too long.Email(mal: 'Malformed email'), // "mal" is the error message in case of malformed email.
]),
);
}
Or — even better — use the compound validator ReqEmail to perform the same
task.
logic
— validation logic and unit testing (Equal, Ok, Nok, ValueBack).
net —
internet (Email, Ipv4, Ipv6, MacAddr, Url, etc.).
numeric
— validators related to numbers or digits (Digit, Hex, Int, Num, etc.).
Demo application
The demo application provides a fully working example, focused on demonstrating
exactly four validators in action — Pair, ReqLen, ReqEmail, and Equal.
You can take the code in this demo and experiment with it.
To run the demo application:
git clone https://github.com/dartoos-dev/formdator.git
cd formdator/example/
flutter run -d chrome
This should launch the demo application on Chrome in debug mode.
Contribute
Contributors are welcome!
Open an issue regarding an improvement, a bug you noticed, or ask to be
assigned to an existing one.
If the issue is confirmed, fork the repository, do the changes on a separate
branch and make a Pull Request.
After review and acceptance, the Pull Request is merged and closed.
Make sure the command below passes before making a Pull Request.