Flutter 颤振中两个容器之间的多余空间
我想删除文本小部件和列表视图(旋转木马滑块)之间的额外空间。这两个小部件都嵌入到容器小部件中。我没有在这两个小部件之间添加任何SizedBox或间隔。我不知道为什么这个额外的空间会来! 下面是示例代码-Flutter 颤振中两个容器之间的多余空间,flutter,dart,Flutter,Dart,我想删除文本小部件和列表视图(旋转木马滑块)之间的额外空间。这两个小部件都嵌入到容器小部件中。我没有在这两个小部件之间添加任何SizedBox或间隔。我不知道为什么这个额外的空间会来! 下面是示例代码- class _DashBoardState extends State<DashBoard> { @override Widget build(BuildContext context) { return Scaffold( body: Column(
class _DashBoardState extends State<DashBoard> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
SizedBox(
height: 50,
),
Container(
child: Text(
'First Text Box',
style: TextStyle(
fontSize: 22,
),
),
),
Container(
height: 220,
child: ListView(
children: <Widget>[
CarouselSlider(
height: 180.0,
enlargeCenterPage: true,
autoPlay: true,
aspectRatio: 16 / 9,
autoPlayCurve: Curves.fastOutSlowIn,
enableInfiniteScroll: true,
autoPlayAnimationDuration: Duration(milliseconds: 800),
viewportFraction: 0.8,
items: [
Container(
margin: EdgeInsets.all(5.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
image: DecorationImage(
image: NetworkImage(
"https://images.pexels.com/photos/2116475/pexels-photo-2116475.jpeg?
auto=compress&cs=tinysrgb&dpr=2&w=500"),
fit: BoxFit.cover,
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
'Usable Flower for Health',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 18.0,
),
),
Padding(
padding: const EdgeInsets.all(15.0),
child: Text(
'Lorem Ipsum is simply dummy text use for printing and type script',
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
),
textAlign: TextAlign.center,
],
),
],
),
)
] ,
),
);
}
}
class\u仪表板状态扩展状态{
@凌驾
小部件构建(构建上下文){
返回脚手架(
正文:专栏(
儿童:[
大小盒子(
身高:50,
),
容器(
子:文本(
“第一个文本框”,
样式:TextStyle(
尺寸:22,
),
),
),
容器(
身高:220,
子:ListView(
儿童:[
旋转滑翔机(
高度:180.0,
放大中心页:正确,
自动播放:对,
专题:16/9,
自动播放曲线:Curves.FastOutSwowin,
启用无限滚动:正确,
autoPlayAnimationDuration:持续时间(毫秒:800),
视口分数:0.8,
项目:[
容器(
边距:所有边缘集(5.0),
装饰:盒子装饰(
边界半径:边界半径。圆形(10.0),
图像:装饰图像(
图片:NetworkImage(
"https://images.pexels.com/photos/2116475/pexels-photo-2116475.jpeg?
自动=压缩&cs=tinysrgb&dpr=2&w=500“,
适合:BoxFit.cover,
),
),
子:列(
mainAxisAlignment:mainAxisAlignment.center,
crossAxisAlignment:crossAxisAlignment.center,
儿童:[
正文(
“有益健康的花”,
样式:TextStyle(
颜色:颜色,白色,
fontWeight:fontWeight.bold,
字体大小:18.0,
),
),
填充物(
填充:常数边集全部(15.0),
子:文本(
“Lorem Ipsum只是用于打印和键入脚本的虚拟文本”,
样式:TextStyle(
颜色:颜色,白色,
字体大小:15.0,
),
textAlign:textAlign.center,
],
),
],
),
)
] ,
),
);
}
}
我认为额外的空间来自ListView的默认填充。
从文件中:
默认情况下,ListView将自动填充列表的可滚动末端,以避免MediaQuery填充指示的部分障碍。若要避免此行为,请使用零填充属性覆盖
加:
padding:EdgeInsets.all(0)
在ListView
小部件中,将其设置为0
我用你的代码示例尝试了这一点,它正确地删除了多余的空间。你的旋转木马是什么?你使用的是旋转木马滑块软件包吗?你说它是一个列表视图,但列表视图没有所有这些属性。你能提供旋转木马的代码(至少是最小的代码)吗为了能够复制?我在pubsec.yaml文件中使用了这个版本的Carousel Slider:Carousel_Slider:^1.4.1Thanks!成功了