I have a RefreshIndicator contained within a StreamBuilder. Anytime the Streambuilder has new data added, the RefreshIndicator rebuilds its Listview.Builder jumping to the top in the process.
StreamBuilder( stream: apiResultStream.stream, builder: (BuildContext context, AsyncSnapshot snapshot) { if(snapshot.hasError){ print("has error"); } 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(),
))
);