fix: use didUpdateWidget to scroll to new initial index
This commit is contained in:
@@ -353,6 +353,20 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
MessageListController get _messageListController =>
|
MessageListController get _messageListController =>
|
||||||
widget.messageListController ?? _defaultController;
|
widget.messageListController ?? _defaultController;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(MessageListView oldWidget) {
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
if (widget.initialScrollIndex != oldWidget.initialScrollIndex ||
|
||||||
|
widget.initialAlignment != oldWidget.initialAlignment) {
|
||||||
|
initialIndex = _initialIndex;
|
||||||
|
initialAlignment = _initialAlignment;
|
||||||
|
_scrollController?.jumpTo(
|
||||||
|
index: initialIndex,
|
||||||
|
alignment: initialAlignment,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => MessageListCore(
|
Widget build(BuildContext context) => MessageListCore(
|
||||||
paginationLimit: widget.paginationLimit,
|
paginationLimit: widget.paginationLimit,
|
||||||
@@ -472,9 +486,6 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
_inBetweenList = true;
|
_inBetweenList = true;
|
||||||
},
|
},
|
||||||
child: ScrollablePositionedList.separated(
|
child: ScrollablePositionedList.separated(
|
||||||
key: _upToDate
|
|
||||||
? null
|
|
||||||
: ValueKey(initialIndex + initialAlignment),
|
|
||||||
itemPositionsListener: _itemPositionListener,
|
itemPositionsListener: _itemPositionListener,
|
||||||
initialScrollIndex: initialIndex,
|
initialScrollIndex: initialIndex,
|
||||||
initialAlignment: initialAlignment,
|
initialAlignment: initialAlignment,
|
||||||
|
|||||||
Reference in New Issue
Block a user