如何为容器提供以后可以更改的首选高度?
How do I give a container a preferred height that can later be changed?
这是我的 Container
:
Container(
height: height - height * 0.4, //this is my preferred height.
width: width - width * 0.7,
decoration: decoration,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 25.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Image.asset(
'assets/opensource.png',
scale: 1.35,
),
text('Open Source Software', 20, Color(0xFF02bbe5)),
text('Contributor since December, 2020', 16,
Color(0xFF02bbe5)),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: text(
'test',
16,
Colors.blueGrey),
),
],
),
),
),
我需要让应用程序响应,因为当内部小部件不能正确放入 Container
时,Container
需要被拉长。
如何为此 Container
指定首选高度,同时允许它在溢出时自由调整大小?
注意:此 Container
位于 Column
自身内,SingleChildScrollView
为父级。我正在构建一个 web
应用程序。
编辑:我使用 MediaQuery 获取宽度和高度。
如果你想让你的应用程序在 Flutter 中响应,那么你应该 Sizer
包( Here )。这个包将使您的应用程序响应任何屏幕尺寸,它分为百分比。例如:
Container(
width: 20.w, //It will take a 20% of screen width
height:30.h //It will take a 30% of screen height
)
有多种方法可以解决这个问题。您可以将容器包装在 AspectRatio
小部件和 Expanded.
中
AspectRatio(
aspectRatio: someAspectRatioValue,
child: Expanded(
child Container(...)
)
)
这应该会在不丢失容器形状的情况下扩展项目容器。
您也可以使用 LayoutBuilder 构建整个屏幕,尽管这需要大量的返工。
这是我的 Container
:
Container(
height: height - height * 0.4, //this is my preferred height.
width: width - width * 0.7,
decoration: decoration,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 25.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Image.asset(
'assets/opensource.png',
scale: 1.35,
),
text('Open Source Software', 20, Color(0xFF02bbe5)),
text('Contributor since December, 2020', 16,
Color(0xFF02bbe5)),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: text(
'test',
16,
Colors.blueGrey),
),
],
),
),
),
我需要让应用程序响应,因为当内部小部件不能正确放入 Container
时,Container
需要被拉长。
如何为此 Container
指定首选高度,同时允许它在溢出时自由调整大小?
注意:此 Container
位于 Column
自身内,SingleChildScrollView
为父级。我正在构建一个 web
应用程序。
编辑:我使用 MediaQuery 获取宽度和高度。
如果你想让你的应用程序在 Flutter 中响应,那么你应该 Sizer
包( Here )。这个包将使您的应用程序响应任何屏幕尺寸,它分为百分比。例如:
Container(
width: 20.w, //It will take a 20% of screen width
height:30.h //It will take a 30% of screen height
)
有多种方法可以解决这个问题。您可以将容器包装在 AspectRatio
小部件和 Expanded.
AspectRatio(
aspectRatio: someAspectRatioValue,
child: Expanded(
child Container(...)
)
)
这应该会在不丢失容器形状的情况下扩展项目容器。
您也可以使用 LayoutBuilder 构建整个屏幕,尽管这需要大量的返工。