flutter_form_validation 0.1.0
flutter_form_validation: ^0.1.0 copied to clipboard
A collection of reusable form widgets for Flutter — validated text fields with presets (email, password, phone, name), built-in validators, and loading button with error display.
flutter_form_validation #
A collection of reusable form widgets for Flutter.
Features #
✅ ValidatedTextField #
TextFormField with built-in validators and presets:
// Email — format validation built-in
ValidatedTextField.email(controller: emailC, label: 'Email');
// Password — min length + visibility toggle
ValidatedTextField.password(controller: passC, label: 'Password');
// Phone — Indonesian format (08xx...)
ValidatedTextField.phone(controller: phoneC, label: 'No. Telepon');
// Name — capitalisation + required
ValidatedTextField.name(controller: nameC, label: 'Nama Lengkap');
// Custom — multiple validators
ValidatedTextField(
controller: codeC,
label: 'Kode Unik',
validators: const [
RequiredValidator(),
MinLengthValidator(4),
PatternValidator(r'^[A-Z0-9]+$'),
],
);
✅ Built-in Validators #
| Validator | Description |
|---|---|
RequiredValidator |
Field tidak boleh kosong |
MinLengthValidator |
Minimal panjang karakter |
MaxLengthValidator |
Maksimal panjang karakter |
EmailValidator |
Format email valid |
PasswordValidator |
Min length + uppercase + number |
PhoneValidator |
Format Indonesia (08xx...) |
PatternValidator |
Regex pattern |
ConfirmValidator |
Cocok dengan field lain |
✅ LoadingButton #
Button dengan loading spinner, success state, dan error message:
LoadingButton(
isLoading: isLoading,
label: 'Login',
onPressed: _submit,
errorMessage: errorMessage, // Auto-shown below button
);
Getting started #
dependencies:
flutter_form_validation: ^0.1.0
flutter pub get
Usage #
Basic form #
class LoginForm extends StatefulWidget {
@override
State<LoginForm> createState() => _LoginFormState();
}
class _LoginFormState extends State<LoginForm> {
final _formKey = GlobalKey<FormState>();
final _emailC = TextEditingController();
final _passC = TextEditingController();
bool _isLoading = false;
String? _error;
Future<void> _submit() async {
if (!_formKey.currentState!.validate()) return;
setState(() => _isLoading = true);
try {
await authService.login(_emailC.text, _passC.text);
} catch (e) {
setState(() => _error = e.toString());
} finally {
setState(() => _isLoading = false);
}
}
@override
Widget build(BuildContext context) {
return Form(
key: _formKey,
child: Column(
children: [
ValidatedTextField.email(controller: _emailC),
const SizedBox(height: 16),
ValidatedTextField.password(controller: _passC),
const SizedBox(height: 24),
LoadingButton(
isLoading: _isLoading,
label: 'Login',
onPressed: _submit,
errorMessage: _error,
),
],
),
);
}
}
API #
ValidatedTextField #
| Parameter | Type | Default |
|---|---|---|
controller |
TextEditingController |
(required) |
label |
String? |
preset-based |
hint |
String? |
preset-based |
validators |
List<FormValidator> |
[] |
enabled |
bool |
true |
obscureText |
bool |
false |
obscureNotifier |
ValueNotifier<bool>? |
null |
keyboardType |
TextInputType? |
per preset |
textInputAction |
TextInputAction? |
per preset |
maxLines |
int? |
1 |
prefixIcon |
Widget? |
per preset |
suffixIcon |
Widget? |
password toggle |
LoadingButton #
| Parameter | Type | Default |
|---|---|---|
isLoading |
bool |
(required) |
label |
String |
(required) |
onPressed |
VoidCallback? |
(required) |
isSuccess |
bool |
false |
errorMessage |
String? |
null |
loadingLabel |
String? |
null |
successLabel |
String? |
'Berhasil' |
height |
double |
48 |
borderRadius |
double |
12 |
backgroundColor |
Color? |
theme primary |
icon |
Widget? |
null |
License #
MIT