3

I have a text field in bottomsheet of Scaffold, and want to take countinuous input without closing window.

for that after taking input i m trying to focus again on textfield but this method is not working

Let me explain below code:

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),), 
                  ],)
                )
              ),
          ],)

         );
        })

This is code of bottomsheet of my scaffold. I m just taking inpust in bottom sheet and displaying in body of Scaffold I wanted these two parts seprate so I used body, bottomsheet But when i display my list in body the focus of textfield in bottomsheet is gone and can be focused only if I click on TextField

As the element entered in textfield the body keeps updating so the control on bottomsheet is lost

Main Problem: "I just want to keep taking input in bottomsheet and diplay it in body with keeping Keyboard countinuously open"

Please help me with this problem

GAMBLER
  • 31
  • 1

0 Answers0