5 Best Form Helper (Validator) Packages for Flutter in 2023
A form is a continuous process of collecting information from an individual that creates a record. In other words, it’s the set of questions you ask to get someone’s contact info or to learn about their preferences. Forms are everywhere! They’re used in places as diverse as medical offices, shopping malls, and government agencies.
Form validation helps us to ensure that the user is submitting the correct data. It can also help to prevent malicious submissions, such as spam or code injection. By validating the form data on the client-side, we can give users immediate feedback about their input. This is especially important for mobile users, who may not have the best keyboard or the easiest time submitting information.
Forms are also a key part of the web and mobile apps. When it comes to creating forms in your app, you have a few options: you can create the form’s user interface (UI) yourself, use a third-party library, or use a form builder provided by your app development platform. In this article, we’ll take a look at five of the best form helper packages for Flutter.
The Best Form Helper Packages
flutter_form_builder
This package helps remove the boilerplate needed to build a form, validate fields, react to changes, and collect final user input. Plus, it includes ready-made input fields for FormsBuilder so you can add common inputs with ease.
The currently supported fields include:
FormBuilderCheckbox
– Single Checkbox fieldFormBuilderCheckboxGroup
– List of Checkboxes for multiple selectionFormBuilderChoiceChip
– Creates a chip that acts like a radio button.FormBuilderDateRangePicker
– For selection of a range of datesFormBuilderDateTimePicker
– ForDate
,Time
andDateTime
inputFormBuilderDropdown
– Used to select one value from a list as a DropdownFormBuilderFilterChip
– Creates a chip that acts like a checkbox.FormBuilderRadioGroup
– Used to select one value from a list of Radio WidgetsFormBuilderRangeSlider
– Used to select a range from a range of valuesFormBuilderSegmentedControl
– For selection of a value using theCupertinoSegmentedControl
widget as an inputFormBuilderSlider
– For selection of a numerical value on a sliderFormBuilderSwitch
– On/Off switch fieldFormBuilderTextField
– A Material Design text field input.
formz
This powerful library makes it easy to create and validate forms in a generic way, without all the hassle. So save yourself some time – and headaches!
final validInputs = <FormzInput>[ NameInput.dirty(value: 'may'), NameInput.dirty(value: 'june'), NameInput.dirty(value: 'december'), ]; print(Formz.validate(validInputs));
form_field_validator
It provides all the common validation options you need to ensure your data is accurate and complete. Plus, it’s easy to use and integrate into your existing code. You can add the validator property to an existing text field like this:
TextFormField( validator: EmailValidator(errorText: 'enter a valid email address') );
reactive_forms
If you’re looking for a model-driven approach to handling form inputs and validations, try reactive_forms! This library is heavily inspired by Angular Reactive Forms, so if you’re familiar with that library, you’ll feel right at home with reactive_forms.
final form = FormGroup({ 'name': FormControl<String>(validators: [Validators.required]), 'email': FormControl<String>(validators: [ Validators.required, Validators.email, ]), });
form_validator
form_validator is a simple and reliable form validation for Flutter form widgets. It has no dependencies, supports localization, is easily extensible, and has been well tested.
TextFormField( validator: ValidationBuilder().email().maxLength(50).build(), decoration: InputDecoration(labelText: 'Email'), ),
Requirements:
- Dart SDK: >=2.12.0 <3.0.0
- Flutter: >= 2.8.0