Flutter - ListView.builder: Initial scroll position Flutter - ListView.builder: Initial scroll position dart dart

Flutter - ListView.builder: Initial scroll position


You can set one of ScrollController's property: initialScrollOffset

But on the condition that you know the offset position of the target item/index.

ScrollController _controller = ScrollController(initialScrollOffset: itemHeight * index)

(note that this example assumes that the sizes of your list's widgets are of constant size, but if you don't have constant widget sizes in your list, then you must be able to calculate the final offset position of your target item - and that is a whole other issue)

Or, if you want it to always be the last item/index, then it's much easier:

ScrollController _controller = ScrollController(initialScrollOffset: _controller.position.maxScrollExtent)


for avoid error where scroll isnt attached for any list, use, WidgetsBinding to pullout after build is ready.

void _scrollToBottom() {    if (_scrollController.hasClients) {      _scrollController.animateTo(_scrollController.position.maxScrollExtent,          duration: Duration(milliseconds: 300), curve: Curves.elasticOut);    } else {      Timer(Duration(milliseconds: 400), () => _scrollToBottom());    } }@overrideWidget build(BuildContext context) {  WidgetsBinding.instance.addPostFrameCallback((_) => _scrollToBottom());  {...} //rest of code;}


The solution for me was:

SingleChildScrollView(                reverse: true,                child: Container(),              ),

ListView has also reverse property.