Form Field flutter code example
Example 1: flutter text field form
TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Enter a search term'
),
);
Example 2: text form field flutter
TextFormField(
decoration: InputDecoration(
labelText: 'Enter your username'
),
);
Example 3: validator flutter
final passwordValidator = MultiValidator([
RequiredValidator(errorText: 'password is required'),
MinLengthValidator(8, errorText: 'password must be at least 8 digits long'),
PatternValidator(r'(?=.*?[#?!@$%^&*-])', errorText: 'passwords must have at least one special character')
]);
String password;
Form(
key: _formKey,
child: Column(children: [
TextFormField(
obscureText: true,
onChanged: (val) => password = val,
validator: passwordValidator,
),
TextFormField(
validator: (val) => MatchValidator(errorText: 'passwords do not match').validateMatch(val, password),
)
]),
);