颤振:聚焦TextView时无法打开屏幕键盘

时间:2019-04-23 23:35:29

标签: firebase dart flutter firebase-authentication textview

我正在尝试使用Firebase身份验证(电子邮件/密码)为应用创建简单的登录和注册屏幕。在物理设备和仿真器上进行测试时,如果将TextView对准焦点,则不会弹出屏幕键盘。有时候,我无法识别的另一个屏幕在一秒钟后突然弹出,但并非每次都弹出。

当我意识到我忘了导入async之后,它就工作了一次,而且似乎可行。稍后恢复处理后,突然键盘又没有打开。我尝试删除几乎所有代码并仅保留UI,但是屏幕键盘没有显示。

代码

void main() => runApp(MaterialApp(title: 'Login Test', home: LoginScreen()));

final FirebaseAuth _auth = FirebaseAuth.instance;
class LoginScreen extends StatelessWidget {
    TextEditingController _uname = TextEditingController();
    TextEditingController _pword = TextEditingController();

    Future<FirebaseUser> _handleSignIn(var context, String email, String password) async{
        AlertDialog dialog = new AlertDialog(
            content: new Text("Loading...")
        );
        showDialog(context: context, builder: (BuildContext context) => dialog);
        _auth.signInWithEmailAndPassword(email: email, password: password).then((FirebaseUser user) {
            print("success");
        }).catchError((e) => print(e));
        Navigator.pop(context);
        return _auth.currentUser;
    }

    @override
    Widget build(BuildContext context) {
            Container loginScreen;
            TextField username = TextField(controller: _uname, decoration: InputDecoration(labelText: "Email",), keyboardType: TextInputType.emailAddress, );
            TextField password = TextField(controller: _pword, decoration: InputDecoration(labelText: "Password",), keyboardType: TextInputType.text, obscureText: true,);
            RaisedButton login = RaisedButton(child: Text("Login"),
                onPressed: (){ _handleSignIn(context, _uname.text.toString(), _pword.text.toString()); }
            );
            loginScreen = Container(child: Column(children: [username, password, login]), padding: EdgeInsets.all(16));
            return Scaffold(appBar: AppBar(title: "Login Screen"), body: loginScreen); 
    }
}

Flutter Doctor输出:

[√] Flutter (Channel stable, v1.0.0, on Microsoft Windows [Version 10.0.17763.437], locale en-US)
• Flutter version 1.0.0 at C:\flutter
• Framework revision 5391447fae (5 months ago), 2018-11-29 19:41:26 -0800
• Engine revision 7375a0f414
• Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

[√] Android toolchain - develop for Android devices (Android SDK 28.0.3)
• Android SDK at C:\Users\laury\AppData\Local\Android\sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
• All Android licenses accepted.

[√] Android Studio (version 3.4)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 34.0.2
• Dart plugin version 183.5901
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)

[√] VS Code (version 1.30.2)
• VS Code at C:\Users\laury\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 2.22.3

[√] Connected device (1 available)
• moto g 7 • ZY225F2VS7 • android-arm64 • Android 9 (API 28)

• No issues found!

根据我阅读的大多数文档,当重点/选择了 TextView 时,键盘应该打开,但是由于我似乎无法固定的原因,它没有打开。

如何解决此问题?

1 个答案:

答案 0 :(得分:0)

这是bug的某些旧版本中的Flutter。执行flutter upgrade将解决此问题。

link包含有关如何升级抖动的信息