perf(following): 追剧页不可见时不再提前拉观看历史

首页用 IndexedStack 常驻四个 tab,追剧页一启动就会发一次观看历史请求,和首页 feed 抢网络;
改为切到该 tab 时再加载,收藏列表也只在首次可见且为空时补拉。
This commit is contained in:
Vicky authored and trae-solo-agent committed 2026-10-29 11:25:47 +08:00
1 parent 63191b4692
commit 9f7301305e
2 files changed
+38 -4

No files matched your search

+15 -4
View File
@@ -69,10 +69,14 @@ class _FollowingPageState extends State<FollowingPage> {
history: context.read<WatchHistoryRepository>(),
catalog: context.read<CatalogRepository>(),
);
unawaited(_history.load());
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) unawaited(widget.favoriteController.load());
});
// IndexedStack 启动时就会建好本页:不可见时先不拉数据,等切到本 tab 再加载,
// 免得冷启动和首页 feed 抢网络。
if (widget.visible) {
unawaited(_history.load());
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) unawaited(widget.favoriteController.load());
});
}
}
void _onAuthChanged() {
@@ -107,6 +111,13 @@ class _FollowingPageState extends State<FollowingPage> {
super.didUpdateWidget(oldWidget);
if (!oldWidget.visible && widget.visible) {
unawaited(_history.load());
// 启动时本页不可见,收藏没在这里拉过;首次可见时补齐(已有数据就不重复请求)。
// 放在帧后,避免构建期间触发 controller 通知。
if (widget.favoriteController.cards.isEmpty) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) unawaited(widget.favoriteController.load());
});
}
}
if (oldWidget.historyRequest == widget.historyRequest) return;
WidgetsBinding.instance.addPostFrameCallback((_) {