You did not provide an example, but this problem occurs because the initial text of each TextFormField
(probably an empty string) already makes the validation return as false. So, in an initial state, all the TextFormField
may be considered as non-validated.
[...] since each Textformfield has its Validator parameter and there is the Form with the autovalidateMode [...]
Not only the Form owns the property autovalidadeMode
. Each Textformfield individually can also have this property configured.
Try removing this Press from Form
and place directly in each Textformfield:
TextFormField(
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (String value) {
return value.contains('') ? 'Validação do erro' : null;
},
)
The following example, freely adapted from the above documentation page, demonstrates the desired result (can be tested on Dartpad):
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Examplo TextFormField',
home: MyStatefulWidget(),
);
}
}
class MyStatefulWidget extends StatefulWidget {
MyStatefulWidget({Key key}) : super(key: key);
@override
_MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
Widget build(BuildContext context) {
return Material(
child: Center(
child: Form(
child: Wrap(
children: List<Widget>.generate(5, (int index) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: ConstrainedBox(
constraints: BoxConstraints.tight(const Size(200, 50)),
child: TextFormField(
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (String value) {
return value.contains('')
? 'Validação que retorna falsa no valor inicial.'
: null;
},
),
),
);
}),
),
),
),
);
}
}