What is the best way to use ScrollController in the list for scrolling to the bottom of the list after the listview is rendered data from streambuilder using firestore query stream?
What is the best place to use scrollcontroller.jumpto method ?
// initialisation
ScrollController scrollController=ScrollController();
// inside initstate() and build method with 1000ms delay - not working
scrollController.jumpTo(scrollController.position.maxScrollExtent);
// widget inside build method
Expanded(
child: StreamBuilder<DocumentSnapshot>(
stream: Firestore.instance
.collection('Data')
.document(widget.dataID)
.snapshots(),
builder: (context, AsyncSnapshot<DocumentSnapshot> snapshot) {
print("Called");
if (!snapshot.hasData) {
return Text("Loading");
}
var info= snapshot.data.data;
if (info!= null &&
info["messages"] != null &&
info["messages"].length > 0 &&
userList.length > 0) {
return ListView.builder(
controller: scrollController,
itemCount: info["challengeReplies"].length,
itemBuilder: (BuildContext context, int index) {
return ChallengeReplyListItem(
currentUserID: widget.currentUserID,
messagesType: info["messages"][index]["messagesType"],
messagesContent: info["messages"][index]["messagesContent"],
},
);
} else if (isLoading) {
return Center(
child: CircularProgressIndicator(),
);
} else {
return Center(child: Text("No Data Found",style: TextStyle(color: Colors.blueGrey,fontSize: 22,fontWeight: FontWeight.w500),));
}
}),
),
Can anyone suggest a proper solution to handle a scroll to the bottom of the page after the data gets rendered properly.
Thanks.