Skip to content

Commit

Permalink
fix: #64
Browse files Browse the repository at this point in the history
  • Loading branch information
LinXunFeng committed Nov 25, 2023
1 parent bdc075d commit b36169a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/src/utils/src/chat/chat_scroll_observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,27 @@ class ChatScrollObserver {
innerRefItemIndex = _innerRefItemIndex;
innerRefItemIndexAfterUpdate = _innerRefItemIndexAfterUpdate;
innerRefItemLayoutOffset = _innerRefItemLayoutOffset;

// When the heights of items are similar, the viewport will not call
// [performLayout], In this case, the [adjustPositionForNewDimensions] of
// [ScrollPhysics] will not be called, which makes the function of keeping
// position invalid.
//
// So here let it record a layout-time correction to the scroll offset, and
// call [markNeedsLayout] to prompt the viewport to be re-layout to solve
// the above problem.
//
// Related issue
// https://github.com/fluttercandies/flutter_scrollview_observer/issues/64
final ctx = observerController.fetchSliverContext();
if (ctx == null) return;
final obj = ObserverUtils.findRenderObject(ctx);
if (obj == null) return;
final viewport = ObserverUtils.findViewport(obj);
if (viewport == null) return;
if (!viewport.offset.hasPixels) return;
viewport.offset.correctBy(0);
viewport.markNeedsLayout();
}

observeSwitchShrinkWrap() {
Expand Down

0 comments on commit b36169a

Please sign in to comment.