原因是:
_refrshListViewProvider函数里面的 _projrctList函数使用的是
ListView
不能包太多
之前的代码:
ListView外面包了Container,因为_refrshListViewProvider组件的使用是child: _projrctList(projectList), _projrctList函数里面不能包太多层级,最好就一层ListView
Widget _refrshListViewProvider() {
return SmartRefresher(
enablePullDown: true,
enablePullUp: true,
controller: _refreshController,
onRefresh: _onRefresh,
onLoading: _onLoading,
child: _projrctList(projectList),
);
}
Widget _projrctList(projectList) {
return Container(
padding:EdgeInsets.symmetric(horizontal: 16) ,
width: ScreenUtil().setWidth(750),
child: ListView.builder(
itemCount: projectList.length,
itemBuilder: (context, index) {
return new GestureDetector(
child: Container(
........
附上使用方法:
Expanded(
flex: 1,
child:
_refrshListViewProvider (),
),
在最上面初始化
class ProjectState extends State withAutomaticKeepAliveClientMixin {
//初始化一开始加载列表的时候上拉就为true
RefreshController _refreshController = RefreshController(initialRefresh: true);
......
}
使用将上拉封装起来使用
Widget _refrshListViewProvider() {
return SmartRefresher(
enablePullDown: true,
enablePullUp: true,
controller: _refreshController,
onRefresh: _onRefresh,
onLoading: _onLoading,
child: _projrctList(projectList),//布局的内容
);
}
列表
// 列表 ListView.builder外面不能包东西,不能上拉组件无效,会产生不了效果,太多层级会影响效果
Widget _projrctList(projectList) {
return ListView.builder(
itemCount: projectList.length,
itemBuilder: (context, index) {
return new GestureDetector(
child: Container(
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
border: Border(bottom: BorderSide(width: 1, color: Color.fromRGBO(219,219,221,1)) ),
),
padding:EdgeInsets.symmetric(vertical: 16) ,
child: new Row(
children: [
Expanded(
flex: 0,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,//排除Colum默认居中,
children: [
Text(projectList[index]["name"],style: TextStyle(color:Color(0xD90E101A) ,fontSize: 16),),
Text("销售负责人:"+projectList[index]["name2"] ,style: TextStyle(color:Color(0x730E101A) ,fontSize: 14),),
],
),
),
Expanded(
flex: 1,
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,//排除Colum默认居中,
children: [
Text(projectList[index]["state"]==15?"输单":"",style: TextStyle(color: Color(0x730E101A),fontSize: 10),),
Text(getStateString(projectList[index]["state"]) ,style: TextStyle(color:getStaeBackgroundColor(projectList[index]["state"]) ,fontSize: 14),),
]
)
),
],
),
),
onTap: () {
Application.router.navigateTo(context, '/project/project_Detail');
}
);
},
);
}