I'm porting my Swift app to Flutter and I have various textfields for time input so in order for user to only be able to input a valid time, I'm using Bloc to validate it.
Basically at every input I send an ValidateText() event to OpeningTimesBloc with the string and textfield's TextEditingController in textfield's onChanged callback.
onChanged: (String value) {
print('textfield 1 onChanged: called');
BlocProvider.of(context)
.add(ValidatedText(text: value, controller: monMorOp));
},
In OpeningTimesBloc I do the validation and yield a state with the validated string. In OpeningTimesScreen's BlocListener I get and use the new value.
Now my complication is that I have 28 textfield as I have opening and closing time for morning and opening (e.g : TextEditingController monMorOp is Monday morning opening) and closing for afternoon for each weekday.
Do I need 28 TextEditingController and have a state check for each one in the BlocListener as:
if (state is ValidatedTextMonMorOp) {
setState(() {
monMorOp.controller.text = state.text;
});
}
or how can I just pass a reference just one and it will pilot the textfield the has the focus on? Something like this perhaps?
if (state is ValidatedText) {
setState(() {
state.controller.text = state.text;
});
}
As Always many thanks for your time and help.