text_form_field_validator 0.0.3 text_form_field_validator: ^0.0.3 copied to clipboard
A super simple dart function for validating text form field in dart and flutter.
import 'package:flutter/material.dart';
import 'package:text_form_field_validator/text_form_field_validator.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Material App',
home: Scaffold(
appBar: AppBar(
title: Text('Material App Bar'),
),
body: Container(
child: Form(
key: _formKey,
child: Column(
children: [
TextFormField(
validator: (value) => FormValidator.validate(
value,
required: true,
stringFormat: StringFormat.url,
),
),
ElevatedButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
//go to next step
print("validation successful");
}
},
child: Text("Submit"),
),
],
),
),
),
),
);
}
}