I need to auto-validate the initial value of the text form field. The validation is worked well! BUT the initial value does not validate at all.
I set the value of autovalidateMode to AutovalidateMode.always,.
The code of form is:
Form(
autovalidateMode: AutovalidateMode.always,
child:TextInput(),
)
the code of TextInput:
class TextInput extends StatelessWidget {
const TextInput();
@override
Widget build(BuildContext context) {
return Padding(
child: BlocSelector<NoteFormCubit, NoteFormState, NoteContent>(
selector: (state) =>
return state.noteContent,
builder: (context, state) {
return TextFormField(
initialValue:BlocProvider.of<NoteFormCubit>(context).state.noteContent.getValueOrElse(""),
// input text stores inside the state
onChanged: (String value) =>
context.read<NoteFormCubit>().textInputNote(textNote: value),
validator: (String? validator) =>
BlocProvider.of<NoteFormCubit>(context)
.state
.noteContent
.value
.fold(
(l) => l.msg,
(r) => null,
),
);
},
),
);
}
}