简体   繁体   English

Flutter:当焦点文本字段时键盘不显示

[英]Flutter:Keyboard not show when focus TextField

I use "TextField" in my flutter project.In simulator iPhone SE 2nd,the keyboard show in normal.But in simulator iPhone 11 Pro,the keyboard doesn't show.Is there something wrong in my code?Thanks!我在我的颤振项目中使用了“TextField”。在模拟器 iPhone SE 2nd 中,键盘显示正常。但在模拟器 iPhone 11 Pro 中,键盘不显示。我的代码有问题吗?谢谢!

class _LoginWidgetState extends State<LoginWidget> {
  final TextEditingController _userNameController = new TextEditingController();
  final TextEditingController _passwordController = new TextEditingController();

  @override
  Widget build(BuildContext context) {
    _userNameController.addListener(() {});
    _passwordController.addListener(() {});

    return Container(
      width: widget.parentSize.width / 1.5,
      height: widget.parentSize.height / 2,
      child: Column(
        children: [
          TextField(
            autofocus: true,
            controller: _userNameController,
            decoration: InputDecoration(
              prefixIcon: Icon(Icons.people),
              hintText: '请输入用户名',
            ),
          ),
          TextField(
            autofocus: false,
            obscureText: true,
            controller: _passwordController,
            decoration: InputDecoration(
              prefixIcon: Icon(Icons.lock),
              hintText: '请输入密码',
            ),
          ),
          SizedBox(
            width: double.infinity,
            child: RaisedButton(
              color: Color(ARGB.BTN_REGISTER),
              onPressed: () {},
              child: Text('注册'),
            ),
          ),
        ],
      ),
    );
  }
}

Try this 尝试这个看看试试这个试试看

FocusNode focusNode;

class _LoginWidgetState extends State<LoginWidget> {
  final TextEditingController _userNameController = new TextEditingController();
  final TextEditingController _passwordController = new TextEditingController();

  @override
  Widget build(BuildContext context) {
    _userNameController.addListener(() {});
    _passwordController.addListener(() {});

    return GestureDetector(
    onTap: () {
    FocusScopeNode currentFocus = FocusScope.of(context);
        if (!currentFocus.hasPrimaryFocus) {
          currentFocus.unfocus();
        }}

    child: Container(
      width: widget.parentSize.width / 1.5,
      height: widget.parentSize.height / 2,
      child: Column(
        children: [
          TextField(
            focusNode: focusNode,
            autofocus: true,
            controller: _userNameController,
            decoration: InputDecoration(
              prefixIcon: Icon(Icons.people),
              hintText: '请输入用户名',
            ),
          ),
          TextField(
            autofocus: false,
            obscureText: true,
            controller: _passwordController,
            decoration: InputDecoration(
              prefixIcon: Icon(Icons.lock),
              hintText: '请输入密码',
            ),
          ),
          SizedBox(
            width: double.infinity,
            child: RaisedButton(
              color: Color(ARGB.BTN_REGISTER),
              onPressed: () {},
              child: Text('注册'),
            ),
          ),
        ],
      ),
    ));
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter 如何在单击 TextField 时始终隐藏键盘但保持焦点(保持显示光标) - Flutter How to always hide keyboard when click on TextField but keep focus(Keep show cursor) 当 flutter 文本字段中的自动对焦为真时,键盘未显示 - keyboard is not showing when auto focus is true in flutter textfield 当焦点在 TextField 上并且在 Flutter 中打开键盘时,如何向上推送内容? - How to push content up when focus is on TextField and keyboard opens in Flutter? 如何在 Flutter 中专注于 TextField 但不显示键盘? - How to keep focus on TextField but not display keyboard in Flutter? 单击颤动中的字段时,文本字段不显示键盘 - Textfield does not show keyboard when click on the field in flutter Flutter cursor 焦点为真时键盘不显示 - Flutter The cursor and the keyboard does not show when focus is true 编辑文本字段时键盘隐藏文本字段(颤动) - Keyboard hide textfield when editing textfield( flutter) 关闭键盘时从 TextField 中移除焦点 - Remove focus from TextField when the keyboard is dismissed 如何在 Flutter 中为文本字段自动显示键盘 - How to show the Keyboard automatically for a Textfield in Flutter Flutter 带有自定义节点的 TextField 在第一个焦点上隐藏键盘 - Flutter TextField with custom node is hiding keyboard on first focus
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM