I'm making a screen with comments section that has comments & their sub comments.
I use ScopedModel for managing state of the screen.
The data for comments is in a List<-model-> and for subcomments are inside the model->List<-model->. this data is in ScopedModel.
I build a sliverList with SliverChildBuilderDelegate so it builds only widgets that are on screen.
Every comment (current_comment) has a reply button, that, after typing, adds a comment model at the end of (current_comment)model-> List<-model-> and calls notifyListener() on the ScopedModel
Now the newly added subcomment has a tag that identifies it as a new comment.
What I want:
I want that the screen scrolls to the newly added subcomment.
What I tried:
Since the newly added subcomment can be identified by a tag, I add a GlobalKey to that comment widget when its built. and then after build is complete, I scroll to that position using the offset obtained from GlobalKey added to it.
My Problem :
Since the SliverList builds elements which are visible to screen only, the newly added comment is far below the parent comment (because reply comment button is on the parent comment only) and isn't built yet. so the builder hasn't attached the GlobalKey to it yet.
Now, how do I auto-scroll to it?
Since key isn't attached to it yet, how do I locate its position & scroll to it?
Suggest me a way to either build all elements of the Sliverlist at once so the key may be attached to the element or another strategy so to auto-scroll to the newly added comment.