[英]Flutter column shows extra space between widgets in Android
Column widget is showing extra space between consecutive widgets even when using simple containers with their padding set to 0. I have tried using SizedBox, setting mainAxisSize to min but nothing seems to be working.即使使用填充设置为 0 的简单容器,列小部件也会显示连续小部件之间的额外空间。我尝试使用 SizedBox,将 mainAxisSize 设置为 min,但似乎没有任何效果。 Moreover this issue is only appearing in Android OS and not on Web or iOS.
此外,此问题仅出现在Android 操作系统中,而不出现在 Web 或 iOS 中。
My Code:我的代码:
Scaffold(
backgroundColor: Colors.yellow,
appBar: AppBar(
title: Text(title),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
padding: EdgeInsets.zero,
height: 50,
color: Colors.black,
),
Container(
padding: EdgeInsets.zero,
height: 100,
color: Colors.black,
),
SizedBox(
height: 20,
),
Container(
height: 150,
color: Colors.black,
)
],
),
),
)
I have zoomed the image a bit to on the right to display the gap better.我已将图像放大到右侧以更好地显示间隙。 There is a line of space appearing between the 2 containers.
两个容器之间出现了一条空间线。 I have placed another container of 150 height below the column to show the difference between complete opaque and space.
我在柱子下方放置了另一个高度为 150 的容器,以显示完全不透明和空间之间的差异。 I have recreated this same behaviour on Pixel 3 Emulator as well as OnePlus 6T device.
我在 Pixel 3 Emulator 和 OnePlus 6T 设备上重新创建了相同的行为。
Can anybody help me with a fix to this.任何人都可以帮我解决这个问题。 I know this can be solved using Stack and Positioned but I was hoping to find out if this is an issue in Flutter SDK or a fixable widget behaviour.
我知道这可以使用 Stack 和 Positioned 解决,但我希望找出这是 Flutter SDK 中的问题还是可修复的小部件行为。
That's a pretty annoying effect indeed.这确实是一个非常烦人的效果。 And though I can't tell you why this is happening, playing around with it a bit, it seems that giving the Container a BoxDecoration with a Border instead of a color removes the artifacts:
虽然我不能告诉你为什么会发生这种情况,稍微玩弄一下,似乎给 Container 一个带有边框而不是颜色的 BoxDecoration 消除了伪影:
Scaffold(
backgroundColor: Colors.yellow,
appBar: AppBar(
title: Text('title'),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.black),
color: Colors.black,
),
padding: EdgeInsets.zero,
height: 51,
//color: Colors.black,
),
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.black),
color: Colors.black,
),
padding: EdgeInsets.zero,
height: 100,
),
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.black),
color: Colors.black,
),
height: 150,
//color: Colors.black,
)
],
),
),
)
For me answer didn't work (probably because i had clipPath over container but i found similar solution)对我来说,答案不起作用(可能是因为我在容器上有 clipPath 但我找到了类似的解决方案)
decoration: BoxDecoration(
border: Border.all(width: 0, color: Colors.yourColor),
color: Colors.yourColor,
),
In all containers at your column在您色谱柱的所有容器中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.