首页 > 解决方案 > 在颤动的'FocusNode'中,脚手架的底部不起作用

问题描述

我在脚手架的底部有一个文本字段,并且想要在不关闭窗口的情况下进行计数输入。

为此,在接受输入后,我试图再次关注文本字段,但这种方法不起作用

让我解释一下下面的代码:

bottomSheet: BottomSheet(
        onClosing: () {

        },
        builder: (context){ 
          return Container(
          decoration: BoxDecoration(
            color: Colors.white,
            border: Border.all(color: Colors.black)
          ),
          padding: const EdgeInsets.all(10),
            child: (widget.state == true)? Row(children: [
              Container(
                  width: 160,
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(10),
                    boxShadow: [
                      BoxShadow(
                        color: Color.fromRGBO(141, 148, 251, .5),
                        blurRadius: 10,
                        offset: Offset(0, 5))
                      ]
                  ),
                    child: TextFormField(
                      controller: _r,
                      textInputAction: TextInputAction.send,
                      focusNode: _node,
                      autofocus: true,
                      decoration: InputDecoration(
                        fillColor: Colors.deepPurple,
                        prefixIcon: Icon(Icons.person, color: Colors.grey,),
                        hintText: "R",
                        errorText: validate(_r.text),
                        hintStyle: TextStyle(
                          color: Colors.grey,
                        )
                      ),
                      style: TextStyle(color:Colors.deepOrange),
                      keyboardType: TextInputType.number,
                      onFieldSubmitted: (value) {
                        setState(() {
                        val=true;
                        if(value != ""){
                          _addProduct(value);
                        }
                      });
                      FocusScope.of(context).requestFocus(_node); //This line is not working
                      },
                    ),
                    ),
              Container(
                height: 40,
                padding: EdgeInsets.only(left:18),
                child: RaisedButton(
                  color: Theme.of(context).accentColor,
                  onPressed: () {
                    print(_r.text);
                    setState(() {
                      val=true;
                      if(_r.text != ""){
                        _addProduct(_r.text);
                      }
                     FocusScope.of(context).requestFocus(_node); //This line is not working
                    });
                  }, 
                  child: Row(children: [
                    Icon(Icons.local_parking, color: Colors.white,),
                    Text('P', style: TextStyle(color: Colors.white),), 
                  ],)

                ),
              ),

              Container(
                height: 40,
                padding: EdgeInsets.only(left:18),
                child: RaisedButton(
                  color: Theme.of(context).accentColor,
                  onPressed: () {
                     _node.requestFocus(); //This line is not working

                    });
                  }, 
                  child: Row(children: [
                    Icon(Icons.delete, color: Colors.white,),
                    Text('Edit', style: TextStyle(color: Colors.white),), 
                  ],)
                )
              ),
          ],)

         );
        })

这是我的脚手架底页的代码。我只是在底部表中输入并在脚手架的正文中显示我希望这两个部分分开,所以我使用正文,底部表但是当我在正文中显示我的列表时,底部表中的文本字段的焦点消失了,只有当我点击时才能聚焦在文本字段上

由于在文本字段中输入的元素,正文不断更新,因此底部表上的控件丢失

主要问题: “我只想继续在底页中输入并在正文中显示它,同时保持键盘连续打开”

请帮我解决这个问题

标签: flutterkeyboardscaffold

解决方案


推荐阅读