flutter - itemCount 长度留出空间
问题描述
我有一个这样的程序,它没有给出任何错误,但是 item.lengt 占用了整个课程,程序留下空格而不是消除的空格(显示在代码中)。
我无法消除上面的列表,因为我已经完成了那里的索引,但我无法将它弄出来。
return BlocBuilder(
bloc: _lessonsBloc,
builder: (BuildContext context, LessonsState state) {
if (state is LessonsLoading) {
return Center(
child: CircularProgressIndicator(),
);
} else if (state is LessonsLoaded) {
return ListView.builder(
//here need to change
itemCount: state.lessons.length,
itemBuilder: (context, index) {
//Here I eliminate items from my list its because my index here :/
final displayedLessons = state.lessons[index];
if(tab.text == displayedLessons.day){
return ListTile(
title: Text(displayedLessons.name),
subtitle:
Text(displayedLessons.subname),
trailing: _buildUpdateDeleteButtons(displayedLessons),
);
} else{print('nope');}
return ListTile();
},
);
}
return CircularProgressIndicator();
},
);
}
如果我能弄清楚这一点,我会很高兴,但我认为我应该使用另一个小部件。我只需要一个想法。
https://pasteboard.co/Ivr3FjK.jpg
https://pasteboard.co/Ivr4gRU.jpg
https://pasteboard.co/Ivr4piY.jpg
解决方案
一般情况下的解决方案:
每当您想为给定条件(例如)从构建器函数中跳过一个小部件时,只要该给定条件不满足ListView.builder
,就有条件地返回一个没有维度的空。Container()
示例代码(用于 ListView.builder):
ListView.builder
(
itemCount: 10,
itemBuilder: (BuildContext context, int i) {
i=i+1;
if(i%2==0) return Text(i.toString());
else return Container();
}
)
推荐阅读
- sql-server - ORDER BY、SELECT 语句、重复代码
- javascript - 在事件调用上设置间隔 ID 更改
- javascript - Redux(使用 React) - 调度设置加载等的请求操作会导致额外的渲染
- flatbuffers - 将平面缓冲区从 C 传递到 duktape javascript
- c# - 重构代码并开发干净的代码
- c - 调用 gluNewQuadric 时出现“无效值”
- django - 每个虚拟环境都需要 django 吗?
- sql - Rails SQL3 唯一性验证失败
- mysql - 将日期作为 MySQL 存储过程的 IN 参数处理
- android-architecture-components - 如何添加一个函数来删除 ViewModel 中的房间中的所有数据,如下所示