gpt4 book ai didi

flutter - RenderFlex溢出- flutter

转载 作者:行者123 更新时间:2023-12-03 03:15:11 29 4
gpt4 key购买 nike

嗨,我是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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com