Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter ScrollController maxScrollExtent equals to 0.0

I created a design for a chat application, and tried to scroll to end automatically, I used this code

scrollController.animateTo(
          scrollController.position.maxScrollExtent,
          curve: Curves.easeOut,
  duration: const Duration(milliseconds: 500),
 );

nothing happens, ofc the list has the controller applied

child: ListView.builder(
                padding: EdgeInsets.symmetric(vertical: 10),
                shrinkWrap: true,
                controller: scrollController,
                itemCount: chatMessage.length,
                itemBuilder: (context, index) {
                  return ChatBubble(
                    chatMessage: chatMessage[index],
                    isDark: widget._isDark,
                  );
                },
              )

I tried to print the maxScrollExtent to see if something was wrong. Both the max and min scrollExtent are equals to 0.0. The animateTo function is also call in a postFrameCallback. The listview length is always 20 has, for now, it's a simple list.

like image 286
Volnetiks Avatar asked Sep 13 '25 10:09

Volnetiks


1 Answers

For me, the issue was that my ListView was inside a ScrollView. Removing the ScrollView fixed the issue.

like image 55
Tash Pemhiwa Avatar answered Sep 15 '25 23:09

Tash Pemhiwa