如何让两个ListView.builder在同一个滚动条上进行浮动



我正在构建一个非常简单的待办事项列表,我想将其分为两组:上面的未决任务和下面的已完成任务,并标记一个标题,将它们清楚地分隔开来。

然后,我生成了两个列表(_pendientesList和_completasList(,并在每个列表上放置了ListView.builder,然而,当我显示Column时,会观察到_completasList的第一个Scroll,然后是"的Text;完整的";然后是_ endientesList的第二个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,));
},
),
),
),
],
);
} 

我尝试将列包装在SingleChildScrollView中,但没有成功。

如何在同一个Scroll中同时拥有ListView.builder和文本(或将来的按钮(

您可以这样做,而不是两个ListView.builder。两者在同一个滚动列表上查看所有的小部件pendient都在小部件completas之上。

ListView(
children: [
for (var itemPendiente in _pendientesList)
_crearItem(context, alarmaBloc, itemPendiente),
for (var itemCompletas in _completasList)
_crearItem(context, alarmaBloc, itemCompletas),
],
);

最新更新