I want to setup the initial scroll position of a ListView.builder, I want the list to start at the bottom 0.0
If I setup reverse
on the listView of course I get the initial scroll position to be the desired one, but what I need is to have the last children on the bottom, is a chat app.
This is the list builder, MessageItem()
is the chat message
ListView.builder(
shrinkWrap: true,
controller: _scrollController,
itemCount: snapshot.data.documents.length,
padding: EdgeInsets.all(10.0),
itemBuilder: (BuildContext context, int index) =>
MessageItem(
index: index,
document: snapshot.data.documents[index],
myId: myId));
This is the animation I have when someone send
the message
_scrollController.animateTo(
_scrollController.position.maxScrollExtent,
duration: const Duration(milliseconds: 500),
curve: Curves.easeOut);
the animation works okay.
What I want is the list scroll position to be already at the bottom when the user enters the chat room.
initState()
but it throws error: ``` I/flutter (15097): ScrollController not attached to any scroll views. I/flutter (15097): 'package:flutter/src/widgets/scroll_controller.dart': I/flutter (15097): Failed assertion: line 110 pos 12: '_positions.isNotEmpty' ``` Where should I put it so it can be triggered at the beginning? – VelariumListView
is a builder,ListView.builder
, so that is why I need to setup the animation as:_scrollController.position.maxScrollExtent
instead of0.0
but of course this causes an error, it needs somemounting
I guess. – Velarium