dart - 键盘打开时 Flutter 出现溢出错误

标签 dart flutter flutter-layout

我正在设计一个登录页面,当我点击它打开键盘的任何文本表单字段时,它会溢出,并通过这样的溢出警告查看附图。 我还希望凸起按钮图标应该位于按钮的右侧。

Widget build(BuildContext context) {
    return Container(
      child: Scaffold(
        body: Stack(
          fit: StackFit.expand,
          children: <Widget>[
            Container(
              decoration: BoxDecoration(
                  image: new DecorationImage(
                      image: new AssetImage('assets/login_page_bg_1.jpg'),
                      fit: BoxFit.cover,
                      colorFilter: new ColorFilter.mode(
                          Colors.black.withOpacity(0.55), BlendMode.dstATop))),
            ),
            Column(
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                Expanded(
                  flex: 1,
                  child: Container(
                    margin: new EdgeInsets.only(top: 42.0),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        Image.asset('assets/logo.png',
                            width: 250.0, height: 200.21),
                      ],
                    ),
                  ),
                ),
                Expanded(
                  flex: 2,
                  child: Container(
                    margin: new EdgeInsets.only(bottom: 40.0),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        //form filed goes here
                        Text('Login As User',
                            textAlign: TextAlign.center,
                            style: TextStyle(
                                fontWeight: FontWeight.bold, fontSize: 35.0)),
                        TextFormField(
                            keyboardType: TextInputType.emailAddress,
                            decoration: InputDecoration(
                              hintText: 'you@example.com',
                              labelText: 'Email Address',
                            ),
                        new Container(
                          // width: MediaQuery.of(context).size.width,
                          child: RaisedButton.icon(
                            color: Color.fromARGB(251, 188, 74, 1),
                            label: Text('LOGIN'),
                            icon: Icon(Icons.send,
                                size: 10.0, color: Colors.black),
                            onPressed: () {
                              this.submit();
                            }, ),)],),),)],)],),),);

Intital state

Error/overflowed State

最佳答案

将以下属性设置为false

Scaffold(
  resizeToAvoidBottomInset: false, 
  ... 
)

如果您遇到溢出错误问题,请使用 SingleChildScrollView

Scaffold(
  resizeToAvoidBottomInset: false, // set it to false
  body: SingleChildScrollView(child: YourBody()),
)

PS:如果你喜欢在键盘打开时滚动你的小部件,你可以看看this answer

关于dart - 键盘打开时 Flutter 出现溢出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55312583/

相关文章:

flutter - 如何在列表中取消选择带有列表的其余索引?

flutter - Dart 如何实现连续输出的 web-socket

Dart int 和 double 被拘留?被相同()特殊对待?

flutter - 停止在 Textfield 子项上扩展 SliverAppBar 获得焦点

键盘上方的额外/不需要的空间

Flutter ListWheelScrollView ,如何添加水平线

dart - 为什么这个回调在这个 dart 方法中显示为 null

annotations - 如何创建自定义的Polymer和PolymerDart注释?

firebase - 在 Xcode 中存档时 Flutter Firestore 插件抛出错误

flutter - 消除小部件之间的间隙