按钮宽度匹配父项
问题内容:
我想知道如何设置宽度以 匹配父 版面宽度
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
将视图扩展到两个方向,我不知道该怎么做。
问题答案:
正确的解决方案是使用SizedBox.expand
窗口小部件,该窗口小部件将强制其child
匹配其父级的大小。
SizedBox.expand(
child: RaisedButton(...),
)
有很多选择,它们或多或少地允许自定义:
SizedBox(
width: double.infinity,
// height: double.infinity,
child: RaisedButton(...),
)
或使用 ConstrainedBox
ConstrainedBox(
constraints: const BoxConstraints(minWidth: double.infinity),
child: RaisedButton(...),
)