form_flutter 0.0.1
form_flutter: ^0.0.1 copied to clipboard
A Flutter package for reusable forms, validators, and field catalogs.
form_flutter #
A Flutter package for building reusable, schema-friendly forms with shared validation, common field widgets, and preset field catalogs.
Features #
- Reusable form controller for values, errors, and async validation state
- Common field widgets for text, password, multiline, number, dropdown, radio, checkbox, switch, date, time, date-time, slider, and multi-select
- Sync and async validators for text, numbers, dates, files, conditional rules, and uniqueness checks
- Preset field catalog for personal, contact, address, account, academic, professional, survey, commerce, appointment, and consent flows
- Common option sets for fields like gender, marital status, degree, employment type, payment method, and more
Getting started #
Add the package to your pubspec.yaml:
dependencies:
form_flutter: ^1.0.0
Then run:
flutter pub get
Usage #
Import the package:
import 'package:form_flutter/form_flutter.dart';
Create a controller and define your fields:
final controller = FormFlutterController(
initialValues: const {
'fullName': '',
'email': '',
'acceptTerms': false,
},
);
final fields = <FormFlutterField<dynamic>>[
FormFlutterTextField(
name: 'fullName',
label: 'Full name',
validator: FormFlutterValidators.combine([
FormFlutterValidators.requiredText(),
FormFlutterValidators.minLength(3),
]),
),
FormFlutterTextField(
name: 'email',
label: 'Email',
keyboardType: TextInputType.emailAddress,
validator: FormFlutterValidators.combine([
FormFlutterValidators.requiredText(),
FormFlutterValidators.email(),
]),
asyncValidator: FormFlutterValidators.uniqueEmail(
(email, _) async => email != 'taken@example.com',
),
),
FormFlutterCheckboxField(
name: 'acceptTerms',
label: 'I agree to the Terms and Conditions',
validator: FormFlutterValidators.mustBeTrue(),
),
];
Render them with DynamicFormFlutter:
DynamicFormFlutter(
controller: controller,
fields: fields,
submitLabel: 'Submit',
onSubmit: (values) {
debugPrint('Submitted: ${values.asMap()}');
},
)
Validators #
Available validator helpers include:
requiredText,requiredNumber,requiredSelection,requiredDate,requiredTime,requiredValueemail,phone,url,numericText,patternminLength,maxLength,exactLengthminNumber,maxNumberminDate,maxDate,minimumAgesameAsField,requiredIf,conditionalminItems,maxItemsrequiredFile,fileSize,fileExtension,imageOnlystrongPassword,mediumPassword,highStrengthPassworduniqueValue,uniqueUsername,uniqueEmailcombine,combineAsync,custom
Preset catalog #
form_flutter includes metadata presets and option sets to help build real-world forms faster.
Examples:
FormFlutterCatalog.personalInformationFormFlutterCatalog.contactInformationFormFlutterCatalog.addressInformationFormFlutterCatalog.accountFieldsFormFlutterCatalog.professionalFieldsFormFlutterCatalog.appointmentFieldsFormFlutterCatalog.consentFields
Examples of shared option sets:
FormFlutterOptionSets.genderFormFlutterOptionSets.maritalStatusFormFlutterOptionSets.degreesFormFlutterOptionSets.employmentTypesFormFlutterOptionSets.paymentMethods
Additional information #
This repository currently still includes a demo app in lib/main.dart to exercise the package API locally. A future cleanup step is to move that demo into an example/ app for publishing.