flutter - 如何让两个 ListView.builder 在同一个滚动条上颤动?
问题描述
我正在构建一个非常简单的待办事项列表,我想将其分为两组:上面的待处理任务和下面的已完成任务,通过标记清楚地将它们分开的标题。
然后,我生成了两个列表(_pendientesList 和 _completasList)并在每个列表上放置了一个 ListView.builder,但是当我显示列时,观察到第一个 _completasList 滚动,然后是“完成”的文本,然后是第二个 _pendientesList 滚动. 我想要实现的是这三个组件是同一个 Scroll 的一部分。
从 StreamBuilder 生成列表的代码如下:
Widget _crearListado(BuildContext context, AlarmaBloc alarmaBloc) {
final _size = MediaQuery.of(context).size;
List<AlarmaModel> _completasList = new List();
List<AlarmaModel> _pendientesList = new List();
return Column(
children: <Widget>[
Container(
height: _size.height * 0.5,
child: Padding(
padding: const EdgeInsets.only(bottom: 70.0/2, left: 10.0, right: 10.0, top:0.0), //fondo gris del listado. Bottom
child: StreamBuilder(
stream: alarmaBloc.alarmasStream,
builder: (BuildContext context, AsyncSnapshot<List<AlarmaModel>> snapshot){
if (snapshot.hasData) {
final tareasList = snapshot.data;
if (tareasList.length == 0) return _imagenInicial(context);
tareasList.sort((a, b) => a.fechaVencimiento.compareTo(b.fechaVencimiento));
_completasList = tareasList.where((element) => element.completa==true).toList();
_pendientesList = tareasList.where((element) => element.completa==false).toList();
return Column(
children: <Widget>[
Expanded(
child: ListView.builder(
itemCount: _pendientesList.length,
itemBuilder: (context, i) =>_crearItem(context, alarmaBloc, _pendientesList[i]),
padding: EdgeInsets.only(left: 10.0, right: 10.0, top: 10.0, bottom: 20.0),
),
),
SizedBox(height: 10.0,),
Text('Completas '),
Expanded(
child: ListView.builder(
itemCount: _completasList.length,
itemBuilder: (context, i) =>_crearItem(context, alarmaBloc, _completasList[i]),
padding: EdgeInsets.only(left: 10.0, right: 10.0, top: 10.0, bottom: 20.0),
),
),
],
);
} else if (snapshot.hasError) {
return Text(snapshot.error.toString());
}
return Center (child: Image(image: AssetImage('Preloader.gif'), height: 200.0,));
},
),
),
),
],
);
}
我尝试将 Column 包装在 SingleChildScrollView 中,但没有成功。
如何在同一个 Scroll 中同时拥有 ListView.builder 和文本(或将来的按钮)?
解决方案
而不是两个ListView.builder
,你可以这样做。两者都在同一个滚动列表视图上,所有挂件都在小部件completas之上。
ListView(
children: [
for (var itemPendiente in _pendientesList)
_crearItem(context, alarmaBloc, itemPendiente),
for (var itemCompletas in _completasList)
_crearItem(context, alarmaBloc, itemCompletas),
],
);
推荐阅读
- python - 如何让python脚本重新连接IBKR TWS API?东部时间下午 5 点断开连接几乎总是会终止脚本
- python - 如何使用 Python 从网站获取 json 字符串?
- laravel - 如果在 where 组合到 laravel 之间的子句收集
- json - 怎么写一个接一个的JSON数据
- json - 使用groovy从json中删除前导方括号
- performance - 两次引用相同度量时 DAX 性能低下
- python - Heroku在部署python Flask Web应用程序时获取=错误代码= H10
- flutter - Flutter:我想将每个 for 循环中的 String 值分配给 Flutter 中的字符串列表,但出现无效范围的错误
- r - { :需要 TRUE/FALSE 的缺失值
- android - 从 Activity 加载 Fragment 时出现空白屏幕