颤振:无法允许用户输入

时间:2019-04-12 17:45:08

标签: dart flutter

正常情况

enter image description here


打开键盘时

它显示溢出错误

enter image description here


包含resizeToAvoidBottomInset

TextField隐藏在键盘下方

enter image description here


代码:

void main() => runApp(MaterialApp(home: HomePage()));

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // resizeToAvoidBottomInset: false, // including this hides TextField beneath Keyboard
      body: Column(
        children: <Widget>[
          FlutterLogo(size: 500),
          TextField(decoration: InputDecoration(hintText: "  Enter something here ...")),
          Expanded(child: FlutterLogo(size: 300)),
        ],
      ),
    );
  }
}

编辑:

我要的是TextField应该在焦点对准时自动向上滚动,这也意味着FlutterLogo1也应该向上滚动,而FlutterLogo2应该在键盘下面。 (这是Android原生的非常普遍的行为,一切都由您处理)

1 个答案:

答案 0 :(得分:0)

我认为这会起作用。


void main() => runApp(MaterialApp(home: HomePage()));

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // resizeToAvoidBottomInset: false, // including this hides TextField beneath Keyboard
      body: Stack(
        children: <Widget>[
          FlutterLogo(size: 500),
          Column(children: <Widget>[
            Container(
                margin: EdgeInsets.fromLTRB(0.0, 200.0, 0.0, 0.0),
                child: TextField( decoration: InputDecoration(hintText: "  Enter something here ..."))),
            Expanded(child: FlutterLogo(size: 300)),
          ],)

        ],
      ),
    );
  }
}