【问题标题】:How to give AspectRatio as much space as possible如何给 AspectRatio 尽可能多的空间
【发布时间】:2019-01-29 17:38:16
【问题描述】:

我有一个内部带有 AspectRatio 小部件的小部件,当我将它放入 Expanded 时,它的尺寸不正确(这个尺寸不满足给定的 AspectRatio)。 有没有办法为 AspectRatio 获得尽可能多的空间并保持给定的 aspectRatio?

我这样做,得到 100 个单位为黄色,其他所有单位为灰色。而不是配给宽度的灰色矩形:高度等于 2.0。

@override
Widget build(BuildContext context) {

return Scaffold(
  appBar: AppBar(
    title: Text(widget.title),
  ),
  body: Center(
    child: Column(
      children: <Widget>[
        Container(
          height: 100.0,
          color: Colors.yellow,
        ),
        Expanded(
          child: AspectRatio(
            aspectRatio: 2.0,
            child: Container(
              color: Colors.grey,
            ),
          ),
        )
      ],
    ),
  ),
);
}

【问题讨论】:

    标签: user-interface dart flutter aspect-ratio


    【解决方案1】:

    您可以将AspectRatio 小部件包装在AlignCenter 小部件中。

            Expanded(
                          child: Align(
                            alignment: Alignment.topLeft,
                            child: AspectRatio(
                              aspectRatio: 2.0,
                              child: Container(
                                color: Colors.grey,
                              ),
                            ),
                          ),
                        )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-23
      • 2021-08-14
      • 1970-01-01
      • 1970-01-01
      • 2010-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多