Flutter 布局参考手册:IntrinsicWidth 和 IntrinsicHeight

2019-06-1517:01:55APP与小程序开发Comments4,191 views字数 969阅读模式

IntrinsicWidth 和 IntrinsicHeight

想要某行或列中所有部件和最高/最宽的部件一样高/宽?不要乱找了,答案在这里!文章源自菜鸟学院-https://www.cainiaoxueyuan.com/xcx/13672.html

当你有这种样式的布局:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/xcx/13672.html

Flutter 布局参考手册: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文章源自菜鸟学院-https://www.cainiaoxueyuan.com/xcx/13672.html

Flutter 布局参考手册:IntrinsicWidth 和 IntrinsicHeight
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'),
            ),
          ],
        ),
      ),
    ),
  );
}
复制代码

如果你需要的是让所有部件和最高的部件,可以结合使用 IntrinsicHeightRow 部件。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/xcx/13672.html

作者:Yuqi
链接:https://juejin.im/post/5cfe0d136fb9a07efc497d7d
来源:掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/xcx/13672.html

文章源自菜鸟学院-https://www.cainiaoxueyuan.com/xcx/13672.html
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/xcx/13672.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定