[英]How to move up the lable text without moving the hint text in TextFormField (flutter)
I have the following widget tree: SizedBox( child: Container ( child: TextFormField(),),),
我有以下小部件树: SizedBox( child: Container ( child: TextFormField(),),),
I want the labelText to be inline with the container's top edge.我希望 labelText 与容器的顶部边缘内联。 contentPadding: EdgeInsets.fromLTRB(x, x, x, x),
and EdgeInsets.only(x, x, x, x),
hasn't helped at all. contentPadding: EdgeInsets.fromLTRB(x, x, x, x),
和EdgeInsets.only(x, x, x, x),
根本没有帮助。
contentPadding:EdgeInsets.only(left: 10.0, right: 20.0, ),//paddingin InputDecoration
padding: EdgeInsets.only(left: 10.0, right: 20.0,),//padding Container
I have Container 1 which is the initial view.我有 Container 1这是初始视图。
Using the above EdgeInsets I get container 2 .使用上面的 EdgeInsets 我得到容器2 。 What can I do to achieve Container 3 ?我能做些什么来实现 Container 3 ?
Edit编辑
return SizedBox(
height: 105,
child: Container(
decoration: decorationBox.copyWith(
borderRadius: BorderRadius.all(Radius.circular(15.0)),
),
margin: EdgeInsets.all(15.0),
padding: EdgeInsets.only(left: 10.0, right: 20.0,),
width: 350.0,
child: Center(
child: TextFormField(
cursorColor: color,
validator: validate,
obscureText: obscure,
keyboardType: keyboard,
onSaved: onSaved,
decoration: decorationText.copyWith(
hintText: hintText,
labelText: labelText,
prefixIcon: Icon(
icon,
color: color,
size: 40.0,
),
),
),
),
),
);```
have you tried using other widgets in place of SizedBox like UnconstrainedBox, and could you show full code for container to understand the problem more better.您是否尝试过使用其他小部件代替 UnconstrainedBox 等 SizedBox,您能否显示容器的完整代码以更好地理解问题。
So what I have found is, SizedBox simply creates a box with given width/height and doesn't allow child to go beyond given dimensions.所以我发现,SizedBox 只是创建了一个具有给定宽度/高度的盒子,并且不允许孩子 go 超出给定尺寸。
so you can use limited box instead of SizedBox and set margin/padding to text container so that it can go outside box.因此您可以使用受限框而不是 SizedBox 并将边距/填充设置为文本容器,以便它可以在框外 go 。
I hope it works for you.我希望这个对你有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.