flutter ListView中嵌套ListView并对listview用controller监听的问题
现在是碰到这样一个问题 listview中嵌套了一个listview,并需要对内部的listview实现一个上拉刷新的功能,但是controller一直没有监听到。尝试多种方法后,还是将外部的listview改为column,并将内部listview外套一个expanded。这样,解决了问题。
代码结构如下 红框是内外两个部分
内部listview 关键是使用 controller: _scrollController,shrinkWrap: true,并用expaned撑开容器
ListView.builder(
shrinkWrap: true,
itemCount: this.showAct.length,
controller: _scrollController,
itemBuilder: (context, index) {
if (index < showAct.length) {
return ListTile(
onTap: () {
// print(showAct[index]['id']);
Navigator.pushNamed(context, '/myTeamDetailPage', arguments: {
"id": showAct[index]['id'],
"chooseId": chooseId,
"isFormMyPage": true
});
},
subtitle: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
"人数",
style: TextStyle(color: Colors.grey),
),
SizedBox(
width: 5,
),
Text(
showAct[index]['mbrCount'].toString() ?? "0",
style: TextStyle(color: Color(0xffFE6004)),
),
SizedBox(
width: 5,
),
Text(
"活动数",
style: TextStyle(color: Colors.grey),
),
SizedBox(
width: 5,
),
Text(
showAct[index]['actCount'].toString() ?? "0",
style: TextStyle(color: Color(0xffFE6004)),
)
],
),
leading: ClipRRect(
borderRadius: BorderRadius.circular(5),
child: CachedNetworkImage(
fit: BoxFit.fill,
height: 50,
width: 50,
imageUrl: showAct.isNotEmpty &&
showAct[index]['logo'] != "" &&
showAct[index]['logo'] != null
? showAct[index]['logo']
: 'https://kt-1301681474.cos.ap-shanghai.myqcloud.com/app/rot/lbt_20200425181036.png',
placeholder: (context, url) => CircularProgressIndicator(),
errorWidget: (context, url, error) => Icon(Icons.error),
),
),
title: Text(
chooseId == 2
? this.showAct[index]['objtitle'] ?? ""
: this.showAct[index]['name'] ?? "",
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600),
),
contentPadding: EdgeInsets.symmetric(horizontal: 30.0),
);
} else if (index == showAct.length && showAct.length % 10 == 0) {
if (showAct.isEmpty || isNoMoreItem) return _noMoreItem();
return _buildLoadMoreItem();
} else {
return _noMoreItem();
}
}),