Skip to content

Conversation

@sorewanya
Copy link
Contributor

@sorewanya sorewanya commented Oct 30, 2025

##Background
Messenger Gapopa. Chat page. Scroll in chat.

##Problem to solve
To do: save scroll position when re-entering chat.

Suggested time to implement: ~2 days.

For example: open chat and scroll, after that go to any otherr page or a different chat, then go back to the chat and make sure that the scroll stays exactly the same as it was when leaving the chat.

##Requirements:

the scroll position should be saved when re-entering chat.
when closing the application the scroll position should NOT be saved.
Possible solutions
As a possibility, you can save the ID and offset of the top/bottom element in chat and reuse it. There should be no persist, since remembering the position is not required.

Solution

Save it in the 'static Map' with the key id.val , and in the value the object with the selected object ChatItemId and the offset taken from _topVisibleItem

Checklist

  • Created PR:
    • In draft mode
    • Name contains issue reference
    • Has type and k:: labels applied
  • Before review:
    • Documentation is updated (if required)
    • Tests are updated (if required)
    • Changes conform code style
    • CHANGELOG entry is added (if required)
    • FCM (final commit message) is posted or updated
    • Draft mode is removed
  • Review is completed and changes are approved
    • FCM (final commit message) is approved
  • Before merge:
    • Milestone is set
    • PR's name and description are correct and up-to-date
    • All temporary labels are removed

@sorewanya
Copy link
Contributor Author

sorewanya commented Oct 30, 2025

I've only encountered one case where this functionality doesn't work, when the top object is the last long message. In this case, a jump to the end of the message occurs and I have not found a reason for this behavior given the ignoreElements: true setting.

@SleepySquash
Copy link
Contributor

@sorewanya, this sounds like a bug, I guess.

@SleepySquash SleepySquash added this to the 0.7.0 milestone Nov 3, 2025
@SleepySquash SleepySquash modified the milestones: 0.6.9, 0.7.0, 0.6.10 Nov 11, 2025
@sorewanya
Copy link
Contributor Author

@sorewanya, this sounds like a bug, I guess.

yes, and I think try to solve it by use initIndex and initOffset without call animateTo, problems were the same.

Finaly I use directly listController.sliverController.animateToIndex ...

Unfortunately, I couldn't find the reason for this behavior when scrolling to the very top or scrolling a little past the display of second(of bottom) messages after the last one. animateTo code is supposed to work fine in any situation, but...

@sorewanya sorewanya marked this pull request as ready for review November 17, 2025 13:04
@sorewanya
Copy link
Contributor Author

FCM

Copy link
Contributor

@SleepySquash SleepySquash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your work! Please, take a detailed look at the UX moments I've commented you about - those are essential for frontend application. Those things are first priority always.

Also please don't forget about Effective Dart and Contribution Guide. Those documents exist for the teams to be able to cooperate as efficiently as possible. And the review process shouldn't be considered as an opportunity for someone to comment you about those documents being violated. You should do a self-review ideally with those things in mind before sending the PR for a final review, please.

@SleepySquash SleepySquash modified the milestones: 0.6.11, 0.7.0 Nov 24, 2025
Copy link
Contributor

@SleepySquash SleepySquash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some thoughts I had by looking at the code, please. Take a look, please!

listController.position.pixels >
MediaQuery.of(context).size.height * 2 + 200;
MediaQuery.of(context).size.height * 2 + 200 ||
(_lastVisibleItem?.index ?? 0) > 10;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I understand correctly that this one here is a try to fix the "scroll down" button? Perhaps a different mechanism should be implemented in order for that button to work as intended? I don't really like an idea of adding some more logic just to "patch a hole".

@SleepySquash SleepySquash modified the milestones: 0.6.12, 0.7.0 Dec 1, 2025
@SleepySquash SleepySquash modified the milestones: 0.6.13, 0.7.0 Dec 8, 2025
@SleepySquash SleepySquash modified the milestones: 0.6.14, 0.7.0 Dec 19, 2025
@SleepySquash SleepySquash modified the milestones: 0.7.0, 0.8.0 Dec 25, 2025
@SleepySquash SleepySquash modified the milestones: 0.7.1, 0.8.0, 0.7.2 Jan 7, 2026
@SleepySquash SleepySquash modified the milestones: 0.8.0, 0.9.0 Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improvement of existing features or bugfix k::refactor Refactor changes of existing code k::UI/UX UI (user interface) and UX (user experience) changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[$160] Keep Chat scroll position when leaving and re-entering it

2 participants