本文介绍了按钮宽度匹配父级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何设置宽度以匹配父级布局宽度
I want to know that how can I set a width to match parent layout width
new Container(
width: 200.0,
padding: const EdgeInsets.only(top: 16.0),
child: new RaisedButton(
child: new Text(
"Submit",
style: new TextStyle(
color: Colors.white,
)
),
colorBrightness: Brightness.dark,
onPressed: () {
_loginAttempt(context);
},
color: Colors.blue,
),
),
我对Expanded
小部件了解甚少,但Expanded
将视图扩展到两个方向,我不知道该怎么做.
I know about little bit on Expanded
widget but Expanded
expands view to both direction, i dont know how to do it.
推荐答案
正确的解决方案是使用SizedBox.expand
小部件,该小部件将强制执行其child
以匹配其父级的大小.
The correct solution would be to use the SizedBox.expand
widget, which enforces its child
to match its parent's size.
SizedBox.expand(
child: RaisedButton(...),
)
有很多选择,可以或多或少地进行自定义:
There are many alternatives, which allows for more or less customization:
SizedBox(
width: double.infinity,
// height: double.infinity,
child: RaisedButton(...),
)
或使用ConstrainedBox
ConstrainedBox(
constraints: const BoxConstraints(minWidth: double.infinity),
child: RaisedButton(...),
)
这篇关于按钮宽度匹配父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!