【问题标题】:Not show Next button in the soft keyboard在软键盘中不显示下一步按钮
【发布时间】:2020-07-05 05:26:49
【问题描述】:

安卓工作室 3.6

  @override
  Widget build(BuildContext context) {
    logger.d("build:");
    //String _errorMessage = null;
    return Scaffold(
        key: _scaffoldKey,
        appBar: new AppBar(
            centerTitle: true,
            title: new Text('Sign in',
                style: TextStyle(fontWeight: FontWeight.bold))),
        body: new Container(
            margin: const EdgeInsets.only(
                left: Constants.DEFAULT_MARGIN,
                right: Constants.DEFAULT_MARGIN),
            child: new Form(
                key: _formKey,
                child: new Column(children: [
                  new TextFormField(
                      decoration: new InputDecoration(hintText: 'Email'),
                      keyboardType: TextInputType.emailAddress,
                      onChanged: (value) {
                        setState(() {
                          _email = value;
                        });
                      }),
                  new TextFormField(
                      decoration: new InputDecoration(hintText: 'Password'),
                      obscureText: true,
                      onChanged: (value) {
                        setState(() {
                          _password = value;
                        });
                      })
                ]))));
  }

这里的结果:

重点是第一个字段文本(电子邮件)。但在软键盘上不显示 下一步 按钮(绿色按钮)。显示完成按钮。 为什么?

【问题讨论】:

    标签: android flutter


    【解决方案1】:

    只需添加textInputAction 属性并将TextInputAction.next 枚举分配给它。这将在键盘上显示下一个按钮。 FocusScope 将允许您更改键盘焦点。这里我只是使用nextFocus()在按下next按钮时将键盘焦点更改为下一个TextFormField。

    TextFormField( 
      ...
      textInputAction: TextInputAction.next,
      onFieldSubmitted: (value){
        FocusScope.of(context).nextFocus();
      }
      ...
    )
    

    更多textInputAction类型,请看这个TextInputAction documentation

    【讨论】:

      【解决方案2】:

      如果你想在键盘上看到下一个按钮应该

      TextFormField( 
        ...
        textInputAction: TextInputAction.next,
        ...
      )
      

      但仅此一项不会专注于下一个输入字段。

      请查看:https://medium.com/flutterpub/flutter-keyboard-actions-and-next-focus-field-3260dc4c694How to shift focus to next textfield in flutter?

      【讨论】:

        【解决方案3】:

        您需要指定 textInputAction 属性才能获得该行为。

        TextFormField(
           decoration: new InputDecoration(hintText: 'Email'),
           keyboardType: TextInputType.emailAddress,
           textInputAction: TextInputAction.next,
           onChanged: (value) {
              setState(() {
                 _email = value;
              });
           }
        )
        

        所有可用类型请参考TextInputAction

        【讨论】:

          猜你喜欢
          • 2014-08-30
          • 2013-08-25
          • 1970-01-01
          • 1970-01-01
          • 2011-03-22
          • 2016-02-22
          • 2011-09-13
          • 1970-01-01
          • 2011-09-22
          相关资源
          最近更新 更多