【发布时间】:2021-10-12 16:45:13
【问题描述】:
我有一个包含在 StreamBuilder 中的 RefreshIndicator。每当 Streambuilder 添加了新数据时,RefreshIndicator 都会重新构建其 Listview.Builder,并在此过程中跳转到顶部。
流生成器( 流:apiResultStream.stream, 建设者: (BuildContext 上下文,AsyncSnapshot 快照){ 如果(快照.hasError){ print("有错误"); } if(!snapshot.hasData) {
return RefreshIndicator(
onRefresh: () {
_apiResult=[];
return _loadMoreData(0);
},
child:snapshot.data.length == 0 ? Padding(
padding: const EdgeInsets.all(20.0),
child: Center(child: Text('No items', style: TextStyle(fontSize: 16.0, fontWeight: FontWeight.bold),)),
):SingleChildScrollView(
controller: scrollController,
physics: const AlwaysScrollableScrollPhysics(),
child:ListView.builder(
itemBuilder:(BuildContext ctxt, int index){
return InkWell(
child:TripItem(key: ValueKey(snapshot.data[index].Id),item:snapshot.data[index])
);
}
,itemCount:snapshot.data.length,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
key: UniqueKey(),
))
);
【问题讨论】:
标签: flutter