I have this code in a stateful class The variables
String sth1 ;
String sth2 ;
I need these variables to each get a value from two TextFields once something is inputted. This is what I have
TextField(
autofocus: true,
focusNode: f1,
inputFormatters: [
LengthLimitingTextInputFormatter(1),
],
keyboardType: TextInputType.number,
onChanged: (newVal) {
if (newVal.length == 1) {
newVal = sth1;
f1.unfocus();
FocusScope.of(context).requestFocus(f2);
}
Your onChanged should have sth1 = newVal not newVal = sth1.
Take a
TextEditingController tec = new TextEditingController();
And pass it to the TextField as controller
TextField(controller: tec);
And when you want to get the text just use
tec.text;
Thats it!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With