颤动:无法允许用户输入

问题描述 投票:0回答:1

正常情况

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中是非常常见的行为,一切都是为你处理的)

dart flutter
1个回答
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)),
          ],)

        ],
      ),
    );
  }
}

© www.soinside.com 2019 - 2024. All rights reserved.