“This is the sixth day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

preface

When you log in, the keyboard will pop up normally when you enter the user name, but when you enter the password, the keyboard will disappear and you need to click it again to appear. The same goes for entering a password and then a user name, which only works on Android phones but not iphones. The situation looks like this.

Problem orientation

Not from MAC, but android, and only for password input. It seems likely that the Flutter has a keyboard compatibility issue. Then I ran it on the Android emulator, and it was fine. I have to search the Internet. The search method changed several times, and finally found the corresponding problem by searching “flutter keyboard Disappear Password” on Google. There are quite a few comments about this problem on Flutter github, but they all have one feature, that is, the models of Flutter are all made in Our country, for example:

But give Redmi credit for not entering the password and using the security option.

Judging from Redmi’s feedback, it seems to be the effect of using a secure keyboard for entering passwords. I tried it out on my Honor phone and did have a secure input setting, which is turned on by default, as shown below:

Then I turned the switch off, and sure enough, the problem disappeared! This is apparently the cause of the safe input, presumably because the safe input required switching to a different keyboard, which Flutter did not take into account.

Problem solving

Look at the issue of Flutter (issue 68571), which is still open, indicating that the problem has not been solved yet. Read on for their solution:

Add an additional Listener component to listen for touch events. When focus acquisition is monitored, FocusScope is used to request focus for the corresponding FocusNode, so that the keyboard is actively popped up. Tried, as expected effective 👍🏻. Of course, this method also said that there may be a loss of performance, but generally enter the password interface and services are relatively simple, the overall performance of the application is not affected.

conclusion

This article describes how to solve the problem of the Flutter keyboard disappearing on some Android devices when there is a password input field.

There are actually two ways to solve this problem. One is to disable secure input, but that decision is not up to the developer. Another is to use the Listener component to wrap the input box component, by listening for touch events, to actively get the focus of the pop-up keyboard. In fact, this article is more to tell you a pit of time, how to solve the method – use search!

I am dao Code Farmer with the same name as my wechat official account. This is a column about the introduction and practice of Flutter, providing systematic learning articles about Flutter. See the corresponding source code here: The source code of Flutter Introduction and Practical column. If you have any questions, please add me to the wechat account: island-coder. If you feel you have something to gain, please give three pairs of love as follows:

👍🏻 : a praise to encourage!

🌟 : Collect articles, easy to look back!

💬 : Comment exchange, mutual progress!