Flutter 如何将容器的高度定义为默认值或无
我有一个容器和容器内的图像。我想根据照片的类型定义容器的高度。如果是纵向的,那么高度应该是一个尺寸。如果它是在横向,那么我希望它是在默认高度的一个自动分配Flutter 如何将容器的高度定义为默认值或无,flutter,dart,Flutter,Dart,我有一个容器和容器内的图像。我想根据照片的类型定义容器的高度。如果是纵向的,那么高度应该是一个尺寸。如果它是在横向,那么我希望它是在默认高度的一个自动分配 在下面的例子中考虑身高是虚假的照片 Container( height: isPortrait ? MediaQuery.of(context).size.height / 1.4 : __________ , // How to define something like do nothing child: Cli
在下面的例子中考虑身高是虚假的照片
Container(
height: isPortrait
? MediaQuery.of(context).size.height / 1.4
: __________ , // How to define something like do nothing
child: ClipRRect(
borderRadius: BorderRadius.circular(20),
child: Image.asset(image)
),
),
由于高度是双精度的,所以除了不指定它之外,没有其他真正的方法将其设置为默认值。您可以尝试以下方法:
isPortrait
? Container(
height: MediaQuery.of(context).size.height / 2,
child: RestOfContent())
: Container(
child: RestOfContent(),
),
RestOfContent将是一个包含其余代码的构建器/小部件。这样,您就不必编写重复的代码。为什么不使用mediaquery for landscape,也可以使用mediaquery for landscape for landscape如果需要,我计划添加文本来代替图像。