Open ivk1800 opened 2 years ago
@robert-bitguild may be extends scrollable_positioned_list with keep position? reusing your code?
@robert-bitguild I mean edit PositionedList
, replace SliverList
by FlutterSliverList
and FlutterListViewDelegate
.
I try it, but not work expectably. there are some limitations?
@ivk1800 https://github.com/google/flutter.widgets/pull/318 may resolve the issue
@ivk1800 #318 may resolve the issue looks like commit not work! if it can keep position ,that will be cool!
i tried, but not work. please help to check it . Thanks!
finally. it worked! cause i gave the incorrect key!!
Thanks for commit!
@ivk1800 There are two bugs in my previous PR.
if (widget.itemCount > 0 && widget.onItemKey != null) {
_lastTargetKey = widget.onItemKey!(primary.target);
} else {
_lastTargetKey = null;
}
if (widget.keepPositionWithoutScroll) {
assert(widget.onItemKey != null,
"Please implement onItemKey if keepPositionWithoutScroll was enabled");
if (_lastTargetKey != null) {
var currTargetIndex = _getIndexOfKey();
if (currTargetIndex != null && currTargetIndex > primary.target) {
primary.target++;
}
}
}
I have full push the complete PR. include the example code. You can run example directly. https://github.com/google/flutter.widgets/pull/319
Hope it help for you.
Thanks.
@robert-bitguild If I add more than one item at the same time, it didn't work.
Should we modify
if (widget.keepPositionWithoutScroll) {
assert(widget.onItemKey != null,
"Please implement onItemKey if keepPositionWithoutScroll was enabled");
if (_lastTargetKey != null) {
var currTargetIndex = _getIndexOfKey();
if (currTargetIndex != null && currTargetIndex > primary.target) {
primary.target++;
}
}
}
to
if (widget.keepPositionWithoutScroll) {
assert(widget.onItemKey != null,
"Please implement onItemKey if keepPositionWithoutScroll was enabled");
if (_lastTargetKey != null) {
var currTargetIndex = _getIndexOfKey();
if (currTargetIndex != null && currTargetIndex > primary.target) {
primary.target = currTargetIndex;
}
}
}
Thanks.
@kazemashinobu great, thanks. I have updated the PR which follows your modified code.
By default, if items are inserted at the "top" of a scrolling container like ListView or CustomScrollView, the top item and all of the items below it are scrolled downwards. In some applications, it's preferable to have the top of the list just grow upwards, without changing the scroll position.
https://api.flutter.dev/flutter/widgets/CustomScrollView-class.html#widgets.CustomScrollView.2