[英]How to remove space between widgets in Column or Row in flutter?
There is a gap between the two elements , how to eliminate them?两个元素之间存在差距,如何消除它们? sample code and effect screenshots are as follows :
示例代码和效果截图如下:
code:代码:
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(
color: Colors.red, // Color(0xFF275FF0),
child: Column(
// mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 5),
Container(
height: 100,
color: Colors.white,
),
Container(
height: 100,
color: Colors.white,
),
Container(
height: 100,
color: Colors.white,
),
])))
}
I did not notice those pixels before.我之前没有注意到那些像素。 To avoid that you should use
ListView
instead of Column
.为避免这种情况,您应该使用
ListView
而不是Column
。
Here is an example code with a similar code than yours.这是一个示例代码,其代码与您的代码相似。
return Scaffold(
body: SafeArea(
child: ColoredBox(
color: Colors.red,
child: ListView(
shrinkWrap: true,
children: [
const SizedBox(
height: 5,
),
Container(
height: 100,
color: Colors.white,
),
Container(
height: 200,
color: Colors.white,
),
Container(
height: 300,
color: Colors.white,
)
],
),
),
),
);
I also use ColoredBox
as it is more optimized and specific than Container
我也使用
ColoredBox
因为它比Container
更优化和更具体
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.