Using FocusNode in TextFormField Flutter. I believe this is more or less what you are trying to achieve. You can achieve the same by using onSubmitted or even supplying a unique TextEditingController to your TextFields
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | void main() { runApp(MaterialApp(home: PassCodeExample())); } class PassCodeExample extends StatelessWidget { FocusNode f1 = FocusNode(); FocusNode f2 = FocusNode(); FocusNode f3 = FocusNode(); FocusNode f4 = FocusNode(); @override Widget build(BuildContext context) { return Scaffold( body: Center( child: Padding( padding: const EdgeInsets.all(8.0), child: Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ Flexible( child: TextField( focusNode: f1, keyboardType: TextInputType.number, onChanged: (String newVal) { if (newVal.length == 1) { f1.unfocus(); FocusScope.of(context).requestFocus(f2); } }, decoration: InputDecoration(border: OutlineInputBorder()), ), ), Flexible( child: TextField( focusNode: f2, keyboardType: TextInputType.number, onChanged: (String newVal) { if (newVal.length == 1) { f2.unfocus(); FocusScope.of(context).requestFocus(f3); } }, decoration: InputDecoration(border: OutlineInputBorder()), ), ), Flexible( child: TextField( focusNode: f3, keyboardType: TextInputType.number, onChanged: (String newVal) { if (newVal.length == 1) { f3.unfocus(); FocusScope.of(context).requestFocus(f4); } }, decoration: InputDecoration(border: OutlineInputBorder()), ), ), Flexible( child: TextField( focusNode: f4, keyboardType: TextInputType.number, decoration: InputDecoration(border: OutlineInputBorder()), ), ), ]), ), ), ); } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.