CopyPastor

Detecting plagiarism made easy.

Score: 0.812798023223877; Reported for: String similarity Open both answers

Possible Plagiarism

Reposted on 2021-07-20
by Arsenii Burov

Original Post

Original - Posted on 2020-09-20
by Arsenii Burov



            
Present in both answers; Present only in the new answer; Present only in the old answer;

The solution proposed by @CopsOnRoad works if your feed can expand in one direction only.
[This][1] solution works for appending items to the top and the bottom of the list. The idea of the solution is the following. You create two SliverLists and put them inside CustomScrollView.
``` CustomScrollView( center: centerKey, slivers: <Widget>[ SliverList( delegate: SliverChildBuilderDelegate( (BuildContext context, int index) { return Container( // Here we render elements from the upper group child: top[index] ) } ), SliverList( // Key parameter makes this list grow bottom key: centerKey, delegate: SliverChildBuilderDelegate( (BuildContext context, int index) { return Container( // Here we render elements from the bottom group child: bottom[index] ) } ), ) ```
The first list scrolls upwards while the second list scrolls downwards. Their offset zero points are fixed at the same point and never move. If you need to prepend an item you push it to the top list, otherwise, you push it to the bottom list. That way their offsets don't change and your scroll view does not jump. You can find the solution prototype in the [following][2] dartpad example.

[1]: https://github.com/flutter/flutter/issues/21541#issuecomment-629121578 [2]: https://dartpad.dartlang.org/c3b9b03925cdaaf88c1b8fe78a3b96b0
Ran into this problem recently: I have a chat scroll that async loads previous or next messages depending on the direction of the scroll. [This][1] solution worked out for me. \ The idea of the solution is the following. You create two SliverLists and put them inside CustomScrollView.
CustomScrollView( center: centerKey, slivers: <Widget>[ SliverList( delegate: SliverChildBuilderDelegate( (BuildContext context, int index) { return Container( // Here we render elements from the upper group child: top[index] ) } ), SliverList( // Key parameter makes this list grow bottom key: centerKey, delegate: SliverChildBuilderDelegate( (BuildContext context, int index) { return Container( // Here we render elements from the bottom group child: bottom[index] ) } ), )
The first list scrolls upwards while the second list scrolls downwards. Their offset zero points are fixed at the same point and never move. If you need to prepend an item you push it to the top list, otherwise, you push it to the bottom list. That way their offsets don't change and your scroll view does not jump. \ You can find the solution prototype in the following [dartpad example][2].

[1]: https://github.com/flutter/flutter/issues/21541#issuecomment-629121578 [2]: https://dartpad.dartlang.org/c3b9b03925cdaaf88c1b8fe78a3b96b0

        
Present in both answers; Present only in the new answer; Present only in the old answer;