flutter - RenderFlex溢出- flutter

标签 flutter dart overflow

嗨,我是flutter的新手,并尝试编写我的第一个应用程序,但是Flutter(Dart)RenderFlex溢出像素有问题。

我尝试了多种方法来实现此目标,同时仍使用ListView.Builder,但没有一种有效。什么是完成此操作的更好方法?

我的代码在这里,在此先感谢您的指导

class Register extends StatefulWidget {

final Function toggleView;
Register({ this.toggleView });

@override
_RegisterState createState() => _RegisterState();
}

class _RegisterState extends State<Register> {

final AuthService _auth = AuthService();
final _formKey = GlobalKey<FormState>();
String error = '';
bool loading = false;

// text field state
String email = '';
String password = '';
String confirmpwd ='';

@override
Widget build(BuildContext context) {
  return loading ? Loading() : Scaffold(
    backgroundColor: Colors.white,
    appBar: AppBar(
    backgroundColor: Colors.blue[400],
    elevation: 0.0,
    title: Text('Sign up to Tenant App'),
    actions: <Widget>[
      FlatButton.icon(
        icon: Icon(Icons.person),
        label: Text('Sign In'),
        onPressed: () => widget.toggleView(),
      ),
    ],
  ),
  body: Container(
    padding: EdgeInsets.symmetric(vertical: 20.0, horizontal: 50.0),
    child: Form(
      key: _formKey,
      child: Column(
        children: <Widget>[
          SizedBox(height: 20.0),
          TextFormField(
            decoration: textInputDecoration.copyWith(hintText: 'email'),
            validator: (val) => val.isEmpty ? 'Enter an email' : null,
            onChanged: (val) {
              setState(() => email = val);
            },
          ),
          SizedBox(height: 20.0),
          TextFormField(
            decoration: textInputDecoration.copyWith(hintText: 'password'),
            obscureText: true,
            validator: (val) => val.length < 6 ? 'Enter a password 6+ chars long' : null,
            onChanged: (val) {
              setState(() => password = val);
            },
          ),
          SizedBox(height: 20.0),
          TextFormField(
            decoration: textInputDecoration.copyWith(hintText: 'password'),
            obscureText: true,
            validator: (val) => val != password ? 'Password \'t match' : null,
          ),
          SizedBox(height: 20.0),
          RaisedButton(
            color: Colors.pink[400],
            child: Text(
              'Register',
              style: TextStyle(color: Colors.white),
            ),
            onPressed: () async {
              if(_formKey.currentState.validate()){
                setState(() => loading = true);
                dynamic result = await _auth.registerWithEmailAndPassword(email, password);
                if(result == null) {
                  setState(() {
                    loading = false;
                    error = 'Please supply a valid email';
                  });
                }
              }
            }
          ),
          SizedBox(height: 12.0),
          Text(
            error,
            style: TextStyle(color: Colors.red, fontSize: 14.0),
          )
         ],
       ),
     ),
   ),
 );
}
}

最佳答案

首先,色谱柱的高度不受限制。这意味着它不知道主轴的尺寸,也不知道在哪里渲染子级。

如果不想为其父容器设置大小,则可以使用属性mainAxisSize : MainAxisSize.min

此属性告诉您的列占用所需的最小空间,因此,预先传递的约束没有多大关系。

其次,由于这是Form,因此您需要将容器包装到SingleChildScrollView中,以避免键盘隐藏您的TextFormField
我希望这能解决您的问题!

关于flutter - RenderFlex溢出- flutter ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61201671/

相关文章:

html - 容器溢出,在 Chrome 中很好,在 IE/FF 中很奇怪

ios - 如何在 Flutter 中禁用 InAppWebView 的缩放?

flutter - 我可以向下转换一个类,使它丢失原始的构造函数吗?

android - Flutter 中不显示状态栏

android - Flutter开发(flutter-dev)›需要紧急帮助…由于gradle问题,我无法在android设备中运行flutter应用,并且无法构建apk

dart - 为什么e.currentTarget.id显示警告?

css - 需要下拉菜单在页面加载时具有一定的宽度,但在单击时显示完整的内容长度

html - 将内容框设置为 100% 高,但如果内容只有几行,则无需滚动

mobile - 使用 Flutter 开发 Salesforce

android - 无法在 Flutter 中构建具有多种风格的发布 apk?