Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tab点击切换时会并行提交多个请求 #14

Closed
gitfornncn opened this issue Sep 11, 2019 · 5 comments
Closed

tab点击切换时会并行提交多个请求 #14

gitfornncn opened this issue Sep 11, 2019 · 5 comments

Comments

@gitfornncn
Copy link

首先感谢大大的贡献给我提供很大的帮助!

页面的TabBar,当点击间隔的tab时,会出现将间隔的tab也一起请求。
比如间隔两个tab,那么就会携带两个tab的request请求

@phoenixsky
Copy link
Owner

这不是flutter框架tabview的预加载机制么? 这样打开第二个页面就不需要等待 .类似android的 viewpager.

@gitfornncn
Copy link
Author

但是我看到,切换到中间的tab,还是会请求一遍

@phoenixsky
Copy link
Owner

phoenixsky commented Sep 12, 2019

你仔细看下tab在切换动画的过程. 开启slow animation模式,或者录个慢动作视频
你会发现.假如有A,B,C,D,E,F个tab页,如果直接从A切换到F, 动画到D,E的时候是会有个减速度的,
并不是直接从A到F的. D,F存在一闪而过的状态.
而D,E页面加后,才导致的request的请求.

所以在request后,我会在ViewStateModel中加入以下判断的原因,

  @override
  void notifyListeners() {
    if (!_disposed) {
      super.notifyListeners();
    }
  }

如果你觉得这个问题对你有困扰,可以在request前进行判断
或者直接点到点切换tab

@gitfornncn
Copy link
Author

gitfornncn commented Sep 12, 2019

谢谢您的答复,
我的意思是,现在从A直接切换到F,中间会同时一起包括C,D,E, 3个request请求,然后再从F切换回E时,E页面又重新请求一次,如果是预加载的话,那么切换到E时应该无需再请求了呢

@phoenixsky
Copy link
Owner

phoenixsky commented Sep 16, 2019

这个目前是flutter的bug.可以参考下这个issues
#29225

这里也有个临时解决的办法

@phoenixsky phoenixsky pinned this issue Sep 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants