我的图像与设备屏幕的宽高比不匹配.我想拉伸图像,使其完全填满屏幕,我不想裁剪图像的任何部分.
CSS具有百分比的概念,因此我可以将高度和宽度设置为100%.但看起来Flutter似乎没有这个概念,只是硬编码高度和宽度是不好的,所以我被卡住了.
这就是我所拥有的(我使用的是Stack,因为我在图像的前景中有一些东西):
Widget background = new Container(
height: // Not sure what to put here!
width: // Not sure what to put here!
child: new Image.asset(
asset.background,
fit: BoxFit.fill, // I thought this would fill up my Container but it doesn't
),
);
return new Stack(
children: <Widget>[
background,
foreground,
],
);
Run Code Online (Sandbox Code Playgroud) 如何在flutter中让栈中的孩子等高?下面的容器是自动高度,我需要根据下层容器的高度来设置上层容器的高度。
\n为什么我需要这个\xef\xbc\x9f
\n因为我想实现一个后台进度条。
\nreturn Stack(\n children: [,\n Container(\n //how to auto set this widget equal height to below.\n height:?\n ),\n Container(\n child: Column(\n children: [\n Text("a"),\n Text("b"),\n Text("c"),\n //maybe more widgets..\n ],\n ),\n ),\n ],\n);\nRun Code Online (Sandbox Code Playgroud)\n