gpt4 book ai didi

firebase - Flutter:当 TextView 聚焦时,屏幕键盘不打开

转载 作者:IT王子 更新时间:2023-10-29 06:45:18 25 4
gpt4 key购买 nike

我正在尝试使用 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 医生输出:

[√] 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 处于焦点/被选中时,键盘应该打开,但它没有打开的原因我似乎无法确定。

我该如何解决这个问题?

最佳答案

这是一些旧版本 Flutter 中的一个bug。执行 flutter upgrade 将修复它。

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

关于firebase - Flutter:当 TextView 聚焦时,屏幕键盘不打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55820750/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com