Flutter应用程序-“ RenderFlex被...淹没”和小部件底部

时间:2019-09-26 18:13:59

标签: flutter flutter-layout

我在Flutter应用中创建了登录页面。这是我的原型:

enter image description here

“忘记密码”-应该在页面底部。但是当我输入密码时,我收到一个错误:RenderFlex被溢出了。

enter image description here

这是我的代码:

 Column(
    mainAxisAlignment: MainAxisAlignment.center,
    crossAxisAlignment: CrossAxisAlignment.center,
    mainAxisSize: MainAxisSize.max,
    children: <Widget>[
      FlutterLogo(
        size: 120,
      ),
      Padding(
        padding: EdgeInsets.only(top: 40),
      ),
      Center(
          child: Form(
              child: Column(
        children: <Widget>[
          Padding(
            padding: const EdgeInsets.all(20.0),
            child: TextFormField(
              decoration: InputDecoration(
                  labelText: 'Login', border: OutlineInputBorder()),
              keyboardType: TextInputType.phone,
            ),
          ),
          Padding(
            padding: const EdgeInsets.all(20.0),
            child: TextFormField(
              decoration: InputDecoration(
                  labelText: 'Pass', border: OutlineInputBorder()),
              keyboardType: TextInputType.phone,
            ),
          ),
          SizedBox(
            height: 50.0,
            width: double.infinity,
          ),
          Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: <Widget>[
                Container(
                    height: 48.0,
                    child: RaisedButton(
                        child: Text('Register'),
                        shape: new RoundedRectangleBorder(
                            borderRadius:
                                new BorderRadius.circular(10.0)))),
                Container(
                    height: 48.0,
                    child: RaisedButton(
                        child: Text('Loggin'),
                        shape: new RoundedRectangleBorder(
                            borderRadius: new BorderRadius.circular(10.0))))
              ])
        ],
      ))),
      Expanded(
          child: new Align(
              alignment: Alignment.bottomCenter,
              child: Container(
                  padding: EdgeInsets.only(bottom: 20.0),
                  child: Row(
                    mainAxisSize: MainAxisSize.max,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Text("Forggoten pass?"),
                      GestureDetector(
                          child: Text(
                            "Restore",
                          ),
                          onTap: () {})
                    ],
                  ))))
    ],
  ),

如何解决此问题?

2 个答案:

答案 0 :(得分:2)

我将您的Container调高了,并添加了SingleChildScrollView

class GeneratedMailCouponScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
    return Scaffold(
    appBar: AppBar(),
    backgroundColor: Colors.white,
    body: SafeArea(
        child: SingleChildScrollView(
        child: Container(
            height: MediaQuery.of(context).size.height,
            child: Column(
            children: <Widget>[
                FlutterLogo(
                size: 120,
                ),
                Padding(
                padding: EdgeInsets.only(top: 40),
                ),
                Center(
                child: Form(
                    child: Column(
                    children: <Widget>[
                        Padding(
                        padding: const EdgeInsets.all(20.0),
                        child: TextFormField(
                            decoration: InputDecoration(
                                labelText: 'Login',
                                border: OutlineInputBorder()),
                            keyboardType: TextInputType.text,
                        ),
                        ),
                        Padding(
                        padding: const EdgeInsets.all(20.0),
                        child: TextFormField(
                            decoration: InputDecoration(
                                labelText: 'Pass',
                                border: OutlineInputBorder()),
                            keyboardType: TextInputType.text,
                        ),
                        ),
                        SizedBox(
                        height: 50.0,
                        width: double.infinity,
                        ),
                        Container(
                        child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                            children: <Widget>[
                            Container(
                                height: 48.0,
                                child: RaisedButton(
                                child: Text('Register'),
                                shape: new RoundedRectangleBorder(
                                    borderRadius:
                                        new BorderRadius.circular(10.0),
                                ),
                                ),
                            ),
                            Container(
                                height: 48.0,
                                child: RaisedButton(
                                child: Text('Loggin'),
                                shape: new RoundedRectangleBorder(
                                    borderRadius:
                                        new BorderRadius.circular(10.0),
                                ),
                                ),
                            ),
                            ],
                        ),
                        )
                    ],
                    ),
                ),
                ),
                Expanded(
                child: Container(
                    padding: EdgeInsets.only(bottom: 20.0),
                    child: Row(
                    mainAxisSize: MainAxisSize.max,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                        Text("Forggoten pass?"),
                        GestureDetector(
                            child: Text(
                            "Restore",
                            ),
                            onTap: () {})
                    ],
                    ),
                ),
                )
            ],
            ),
        ),
        ),
    ),
    );
}
}

enter image description here

答案 1 :(得分:1)

在您的Scaffold使用范围内

resizeToAvoidBottomInset: false

然后将Column包裹在SingleChildScrollView