出现键盘时,屏幕上的所有小部件都会被隐藏起来

时间:2018-08-02 08:09:03

标签: dart flutter flutter-layout

我正在使用TabBar和自定义搜索视图,当我在TextField中单击以进行搜索并且键盘弹出我的所有视图皮革时,在下面附加了屏幕截图。这是问题还是我的代码做错了。请看一下我的代码。没有弹出键盘,我的工作正常。

return new Scaffold(

  body: new Container(
    //  margin: EdgeInsets.all(10.0),

      //color: Colors.white30,

      child: new Column(
        children: <Widget>[
          new Container(
              height: 70.0,
              color: Theme.of(context).primaryColor,
              child: new Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: new Card(
                      child: new Container(
                        child: new Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: <Widget>[
                            Padding(
                              padding: const EdgeInsets.only(left: 3.0),
                              child: new Icon(Icons.search),
                            ),

                            new Container(

                              width: MediaQuery.of(context).size.width - 100.0,
                              // Subtract sums of paddings and margins from actual width
                              child: new TextField(
                                controller: controller,
                                decoration: new InputDecoration(
                                    hintText: 'Search', border: InputBorder.none),
                               // onChanged: onSearchTextChanged,
                              ),
                            ),

                            new IconButton(icon: new Icon(Icons.cancel), onPressed: () {
                              controller.clear();
                             // onSearchTextChanged('');
                              FocusScope.of(context).requestFocus(new FocusNode());
                            },),



                          ],
                        ),
                      )
                  ))),
          new Flexible(
            child: new ListView.builder(
                itemCount: productList == null ? 0 : productList.length,
                itemBuilder: (BuildContext context, int index) {

                  return new Container(

                    child: new Column(
                      children: <Widget>[
                        new Container(
                          margin: EdgeInsets.all(10.0),


                          child: new Column(

                            children: <Widget>[
                              new Column(
                                children: <Widget>[
                                  new Padding(padding: const EdgeInsets.only(top: 5.0)),
                                  new Row(
                                    mainAxisAlignment:  MainAxisAlignment.spaceBetween,
                                    children: <Widget>[

                                      new Container(
                                        alignment: FractionalOffset.topLeft ,
                                        width: 250.0,
                                        child: new Column(
                                          mainAxisAlignment: MainAxisAlignment.start,
                                          children: <Widget>[
                                            new Text(productList[index].name,

                                              style: new TextStyle(color: Colors.black,
                                                  fontSize: 18.0, fontWeight: FontWeight.bold),
                                            )

                                          ],
                                        ),
                                      ),


                                      new Text("£"+productList[index].price.toString(),
                                        style: new TextStyle(color: Colors.black,
                                            fontSize: 18.0, fontWeight: FontWeight.bold
                                        ),),

                                    ],
                                  )


                                ],
                              ),

                              new Row(
                                mainAxisAlignment: MainAxisAlignment.start,
                                children: <Widget>[
                                  new Flexible(
                                      child: new Column(
                                        crossAxisAlignment: CrossAxisAlignment.start ,
                                        children: <Widget>[

                                          new Text(

                                            productList[index].description,
                                            overflow:  TextOverflow.fade ,),
                                        ],
                                      ))
                                ],
                              ),

                              new Row(
                                mainAxisAlignment: MainAxisAlignment.end,
                                children: <Widget>[
                                  new  ListTileItemAddRemove(productList[index]),


                                  new Padding(padding: EdgeInsets.only(bottom: 10.0))
                                ],
                              )


                            ],
                          ),
                        ),
                        new Divider(color: Colors.black,)
                      ],
                    ),

                  );

                }),
          ),
        ],
      )


  ),
 );

enter image description here

当我在TextField中单击时,所有小部件都会消失。请参阅下面。

enter image description here

1 个答案:

答案 0 :(得分:2)

我认为在弹出键盘时会调整浮动小部件的大小,我已通过在false内设置resizeToAvoidBottomPadding的值Scaffold解决了此问题。问题已解决,但我仍在寻找问题背后的原因。

return new Scaffold(
  resizeToAvoidBottomPadding : false,
  body: new Container(
  -
  -
  -
  -
  }