Flutter 布局参考手册:IntrinsicWidth 和 IntrinsicHeight
IntrinsicWidth 和 IntrinsicHeight
想要某行或列中所有部件和最高/最宽的部件一样高/宽?不要乱找了,答案在这里!
当你有这种样式的布局:
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('IntrinsicWidth')),
body: Center(
child: Column(
children: <Widget>[
RaisedButton(
onPressed: () {},
child: Text('Short'),
),
RaisedButton(
onPressed: () {},
child: Text('A bit Longer'),
),
RaisedButton(
onPressed: () {},
child: Text('The Longest text button'),
),
],
),
),
);
}
复制代码
但是你希望所有的按钮都和最宽的按钮等宽,只需要使用 IntrinsicWidth
:
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('IntrinsicWidth')),
body: Center(
child: IntrinsicWidth(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
RaisedButton(
onPressed: () {},
child: Text('Short'),
),
RaisedButton(
onPressed: () {},
child: Text('A bit Longer'),
),
RaisedButton(
onPressed: () {},
child: Text('The Longest text button'),
),
],
),
),
),
);
}
复制代码
如果你需要的是让所有部件和最高的部件等高,可以结合使用 IntrinsicHeight
和 Row
部件。
作者:Yuqi
链接:https://juejin.im/post/5cfe0d136fb9a07efc497d7d
来源:掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
THE END