简体   繁体   English

如何在 flutter 上堆叠键盘

[英]How to stack a keyboard on flutter

Currently I have a listview of widgets and I stack a bottom button on the Top of the Stack to be always display.目前我有一个小部件列表视图,我在堆栈顶部堆叠了一个底部按钮以始终显示。 but when I tap on the textfield, the bottom button is push on the top, It's very ugly.但是当我点击文本字段时,底部按钮被推到顶部,非常难看。 How can I push the keyboard over the Button?如何将键盘推到按钮上?

thank you谢谢你在此处输入图像描述

here is a code example:这是一个代码示例:

 class MyHomePage extends StatefulWidget {

 @override
 _MyHomePageState createState() => new _MyHomePageState();
 }

class _MyHomePageState extends State<MyHomePage> {

 final TextEditingController _controller = new TextEditingController();


  @override
  Widget build(BuildContext context) {

  return new Scaffold(
   appBar: new AppBar(
  ),
  body:   new Stack(
      children: <Widget>[

        new ListView(
      children: <Widget>[

            new Column(
              children: <Widget>[
  new Padding(
  padding: const EdgeInsets.all(100.0),),
  new Card(
    child: new Padding(
      padding: const EdgeInsets.all(10.0),
      child: new Row(
        children: <Widget>[
          new Expanded(
            child: new TextField(
              controller: _controller,
              decoration: new InputDecoration(hintText: "Enter an address"),
            ),
          ),

        ],
      ),
    ),
   ),
              ],

            )
          ],
        ),
        new Align
          (
          alignment: Alignment.bottomCenter,

          child :   new RaisedButton(
              child: new  Text("Button", style: TextStyle(color: Colors.black, fontWeight: FontWeight.w700, fontSize: 18.0,)),
              onPressed: (){
              },
              highlightElevation: 4.0,
              highlightColor  : Colors.white,
              shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
          ),
        ),
       ]
      )
    );
  }
}

I would recommend putting the "Button" on the Bottom outside of the Stack inside of a floatingActionButton .我建议将“按钮”放在 Stack 外面的底部,放在floatingActionButton里面。

floatingActionButton: FloatingActionButton.extended(
            elevation: 4.0,
            label: Text(Appliquer),
            onPressed: () {},
          ),
floatingActionButtonLocation:
              FloatingActionButtonLocation.centerDocked,

EDIT AFTER CODE WAS ADDED:添加代码后编辑:
As I said in the comments I would use a FloatingActionButton/BottomNaviagtionBar or a Save-Icon in the AppBar正如我在评论中所说,我会在 AppBar 中使用 FloatingActionButton/BottomNaviagtionBar 或 Save-Icon

Here I added the FloatingActionButton to your code:在这里,我将 FloatingActionButton 添加到您的代码中:

class _MyHomePageState extends State<MyHomePage> {
  final TextEditingController _controller = new TextEditingController();

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        appBar: new AppBar(),
        body: new Stack(children: <Widget>[
          new ListView(
            children: <Widget>[
              new Column(
                children: <Widget>[
                  new Padding(
                    padding: const EdgeInsets.all(100.0),
                  ),
                  new Card(
                    child: new Padding(
                      padding: const EdgeInsets.all(10.0),
                      child: new Row(
                        children: <Widget>[
                          new Expanded(
                            child: new TextField(
                              controller: _controller,
                              decoration: new InputDecoration(
                                  hintText: "Enter an address"),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),

                ],
              )
            ],
          ),
        ],
      ),
      floatingActionButton: FloatingActionButton.extended(
        icon: Icon(Icons.save), label: 
        new Text('Appliquer'), 
        onPressed: () { /*perform your Action here*/ },
      ),
    );
  }
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM