ScrollController not attached to any scroll views.
'package:flutter/src/widgets/scroll_controller.dart':
package:flutter/…/widgets/scroll_controller.dart:1
Failed assertion: line ** pos **: '_positions.isNotEmpty'
This won't be an exact solution to this problem but a work around. I'm trying to build a chat app like Whatsapp. And as you already know, in the screen where you can see the messages in a group or any chat, the scroll starts from the very bottom as you enter the chat.
To achieve this, you have maybe tried to animateTo
maxScrollExtent
like me but it went to nothing but creating a lot of errors like in the title. If you just want to start the list from the bottom every time you enter to that screen or opening and closing the keyboard, all you gotta do is in the answer below.
Use the reverse
property of the ListView.builder
or any scrollable widget to reverse the listing system. As you do this, list you fetch will be shown reversed as well - first item goes to bottom, last item goes to top. To fix this, replace the index
with <yourListName>.length - index - 1
like below. This will "normalize" the sorting of the reversed list.
ListView.builder(
reverse: true,
itemCount: booList.length,
itemBuilder: (context, index)
{
return booList[booList.length - index - 1];
},
),
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.