数据不满一屏是 ,滚动问题--If the data is less than one screen, scrolling problem
https://user-images.githubusercontent.com/32348909/108025589-b2de8c00-7061-11eb-95a8-ff391df0178d.mp4
是这样的,参照scrollable_positioned_list。
我遇到了同样的问题,请问这边的解决方案可以分享一下吗?
Hi, how did you fix this? Thanks
我遇到了同样的问题,请问这边的解决方案可以分享一下吗?
Hi, how did you fix?
如果你想解决这个问题,就需要修改源码。我这里提供一个简单的样例。 If you want to resolve the problem radically, you have to modify the source code. The following code is a distance.
void _scrollTopIndex(String tag) {
int index = _getIndex(tag);
int itemsCountOnScreen = itemPositionsListener.itemPositions.value.length;
if (index != -1) {
//如果要跳转的条目后面的数据个数<屏幕可容纳的数据个数,使用align属性去调整跳转
//条目在屏幕上的位置。align默认是0,即条目的头部top与可视部分上边缘对齐。
//计算正确的对齐位置,才能让它正常显示。
//if the the items'counts after the item you want to jump less than
//full screen items counts, use the align to justify the item's location
// to be correct. The align defaults to be 0, which means the item's top
// to align the view's top.
//change the data of alignment and make it show properly.
if ((widget.data.length - index) < itemsCountOnScreen) {
//可视口由两部分组成,一个是其它数据,一个是期望数据(即想要跳转却不足以填充屏幕的数据)。
//用其他数据个数/总数据个数,作为alignment,就可以让期望数据正确对齐而不发生反弹。
//The view port includes other datas and expected datas(this refers to
//the data you want to jump but can't fill the screen and therefor causes
//out bouncing).
//other datas' length / all datas'length = alignment(the correct rete to align expected datas)
double alignment = (itemsCountOnScreen - (widget.data.length - index)) /
itemsCountOnScreen;
itemScrollController.jumpTo(alignment: alignment, index: index);
} else {
itemScrollController.jumpTo(index: index);
}
}
}
实际效果如下所示,如你所见,我解决了数据不足时跳转反弹的bug。 As you can see, the bug seems to be fixed.
https://user-images.githubusercontent.com/110367679/224910568-e65f47b1-bb41-4e1a-b0b7-5b1e46737c52.mp4
还有更准确的方式,需要获得ListView的可视区域高度,和每一项渲染的高度(像这种等高条目获取一次就够了),通过高度来计算alignment,可以达到更精准的跳转效果。如果要这样做的话,源码就要改更多了。 There is a more accurete way to calculate the alignment. Just get the height of widgets and calculate like above. In this way, you need to modify more source codes.
如果还有其它的这方面的问题,可以艾特我继续回答。虽然我很菜,但是我会努力的! If still have another problems, pls @ me. I will try my best to help you. Forgive my poor english.