flutter-TextField/TextFromField---suffixIcon点击时不弹出键盘

	FocusNode _focusNode=FocusNode();

	TextFormField(
        controller: _pwdController,
        focusNode: _focusNode,
        decoration: InputDecoration(
          icon: Icon(Icons.lock),
          labelText: I18n.of(context).password,
          hintText: I18n.of(context).passwordHint,
          hintStyle: TextStyle(fontSize: 12),
          suffixIcon: IconButton(
            onPressed: () {
            //判断TextFormField是否处于获得焦点的状态,如果没有,当点击图标时禁止TextFormField获取焦点,也就不会弹出软键盘了,当TextFormField获取焦点时,点击图标,不关闭软键盘
              if(!_focusNode.hasFocus){	
                _focusNode.canRequestFocus = false;
                Future.delayed(Duration(milliseconds: 200),(){
                  _focusNode.canRequestFocus = true;
                });
              }
              setState(() {
                _isShowPassWord = !_isShowPassWord;
              });
            },
            icon: Icon(_isShowPassWord ? Icons.visibility_off : Icons.visibility),
          ),
        ),
        validator: (v) =>
            v.trim().length >= 6 ? null : I18n.of(context).passwordError,
        obscureText: _isShowPassWord,
        textInputAction: TextInputAction.done,	//设置软键盘确定按键显示为完成
      );

你可能感兴趣的:(flutter,flutter)