Flutter (Channel stable, 3.13.9, on Microsoft Windows [版本 10.0.22621.4], locale zh-CN)
HUAWEI Mate 30 Pro 5G , HarmonyOS 4.0
The page has two TextFields, one for ordinary text and one for password. When the cursor jumps from the ordinary TextField to the password TextField, the password TextField will lose focus and the keyboard will switch to the secure keyboard. You need to click the password TextField again to gain focus.
I tried the following method but it still doesn’t work
final _accountFocus = FocusNode();
final _passwordFocus = FocusNode();
Column(
children: [
Listener(
onPointerDown: (e) => FocusScope.of(context).requestFocus(_accountFocus),
child: TextField(
focusNode: _accountFocus
),
),
Listener(
onPointerDown: (e) => FocusScope.of(context).requestFocus(_passwordFocus),
child: TextField(
focusNode: _passwordFocus,
obscureText: true,
),
),
],
)
2
Answers
I solved it indirectly using the following method.
By customizing TextInputFormatter, replace the input content with * and save the original content.
Customize a ObscureTextEditingController
Customize a ObscureTextInputFormatter
How to use
text/obscure Text
Did you define these variables under the build() method?
you should define these variables outside of build() method like this: