如何尽可能多地提供 AspectRatio space

How to give AspectRatio as much space as possible

我有一个小部件,里面有 AspectRatio 小部件,当我将它放入 Expanded 时,它的尺寸不正确(这个尺寸不满足给定的 AspectRatio)。 有什么方法可以尽可能多地获得 space 的 AspectRatio 并保持给定的 aspectRatio?

我这样做并得到 100 个单位黄色和所有其他地方灰色。而不是比例 width:height 等于 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,
            ),
          ),
        )
      ],
    ),
  ),
);
}

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

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