'Flutter CustomScrollView how to keep the viewport when adding item at the start of the list?

Problems: For example, there is a list of 100 messages. The current viewport of CustomCrollView is showing message 50 -> 60. When adding a new item to the start of the list, the viewport jumps to message 49 (old) -> 59 (old) (because the scroll offset is not changed so it shifts the content down).

Expected: After adding item, the viewport should keep showing message 50 (old) -> 60 (old).

How can I implement that?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source