CarGuo/gsy_flutter_demo

针对双向聊天列表效果,我这边遇到个问题

Opened this issue · 8 comments

tabbg commented

使用双向聊天列表,加载item高度不一致的数据,比如内部有图片,以及超长的文字,再执行scroller.jumpTo(scroller.position.maxScrollExtent);时会导致到底部的时候会有一个小的跳动。可能是因为scroller.position.maxScrollExtent是一个计算值,跳转到底部的时候,计算的scroller.position.maxScrollExtent大小大于实际的大小导致。请问这种问题有没有解决方案。

CarGuo commented

先 jumpTo 一个 maxScrollExtent - X 的值,然后在 then 里去 scrollto maxScrollExtent 试试

tabbg commented

感谢你的回答。X是取什么值合适点呢?我之前有试过先滚动到maxScrollExtent *0.5然后then0.6-0.7-0.8-0.9-1这种方式,但是任然会有概率会跳动一下。

CarGuo commented

一般我是取 0.7 左右,然后 then 的时候直接就用 animate to 不用 jump 了,在 animate to 的时候重新get maxScrollExtent

tabbg commented

第一次jump到0.7的时候需要延时再去animate不?还有就是我这边RefreshIndicator+physics:const AlwaysScrollableScrollPhysics().applyTo(const BouncingScrollPhysics()),下拉刷新时,偶现会一直触发BouncingScrollPhysics的回弹效果,来回一直弹。我将cacheExtent设置到超级大的情况下才解决了此问题。其核心问题大概也是因为maxScrollExtent 高度不确定导致的。

CarGuo commented

另外一个思路,跳转到末尾滚动期间修改为 ClampingScrollPhysics ,跳转结束后才改为 BouncingScrollPhysics

tabbg commented

这个我试过了,没用 哪怕是ClampingScrollPhysics 也会跳动一下。

CarGuo commented

嗯嗯,我想叉了,jump 直接改的 position ,可以越过 physics ,我以前大概就是这样

   scroller.jumpTo(
                            scroller.position.maxScrollExtent * 0.7);
                        Future.delayed(Duration(milliseconds: 400), () {
                          scroller.animateTo(scroller.position.maxScrollExtent,
                              duration: Duration(milliseconds: 500),
                              curve: Curves.linear);
                        });
```
tabbg commented

嗯,这种方式我也试过,但是不能100%保证不跳动一下。我现在使用的方式就是将cacheExtent的值修改到很大,再附带你所说的跳转方式勉强能达到大部分时间不跳动。但是还是不能保证问题。就想找一下看看有没有什么方式避免这种问题。