[compass_app] UI state never updates for the HomeScreen (regression after the implementation of #2788)
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 55/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- dart
- 领域
- desktop-dev
调研方向
首先跟踪 HomeScreenContainer 中的 HomeViewModel 初始化过程,以及通过 go_router 实现的 HomeScreen 路由行为,并将其与 #2788 之前的重建行为进行比较。通过预订一次行程并返回主页来复现 Windows 流程;完成的标准是新行程无需 hot reload 即可显示,并且相关的状态更新已被覆盖或验证。
由索引模型根据 Issue 内容生成。
描述
Serious bug, application doesn't work the inteded way.
(Flutter 3.44.8; platform: Windows; tested on commit 978919b)
Steps to reproduce:
- Book a new trip;
- Come back to a home screen;
- You can't see new trip, unless you hot reload.
Before moving initialization of HomeViewModel into HomeScreenContainer, it relied on rebuild that go_router did:
- User moves to the home route '/' or deeper;
- All previous routes including the one where user moved are getting rebuilt, which results in creating new instances of viewModels, which results in them calling _load and fetching latest data from repository.
Now it seems that HomeViewModel is just initialized once in HomeScreenContainer and never updates.
Generally according to this statement, the current way go_router "manages" ui states, is wrong, which already was unfolded in issue#2574, but outside of users sharing their ways on how to avoid this behavior, it never really recieved much attention.
So maybe a solution to this bug will also lead to a solution for issue#2574?
I myself temporarly solved issue#2574 in a way where viewModel only updates when user moves directly to a route it was going to. Hopefully this helps:
class RouteLifecycleListener extends StatefulWidget {
const RouteLifecycleListener({
required this.onResume,
required this.child,
super.key,
});
final VoidCallback onResume;
final Widget child;
@override
State<RouteLifecycleListener> createState() => _RouteLifecycleListenerState();
}
class _RouteLifecycleListenerState extends State<RouteLifecycleListener>
with RouteAware {
@override
void didChangeDependencies() {
super.didChangeDependencies();
routeObserver.subscribe(this, ModalRoute.of(context)! as PageRoute);
}
@override
void didPopNext() {
widget.onResume();
}
@override
void dispose() {
routeObserver.unsubscribe(this);
super.dispose();
}
@override
Widget build(BuildContext context) {
return widget.child;
}
}
...
GoRoute(
path: '/home',
name: AppRoute.home.name,
builder: (context, state) => Provider(
create: (context) {
return HomeViewModel(
...
);
},
builder: (context, _) {
return RouteLifecycleListener(
onResume: () => context.read<HomeViewModel>().load.execute(),
child: HomeScreen(viewModel: context.read()),
);
},
),
routes: [ ...
- 主要语言
- Dart
- 星标
- 19.3k
- 派生
- 7.8k
- 平均合并
- 1 天 18 小时
- 30 天内合并 PR
- 4
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
flutter/samples 的其他 Issue
-
[add-to-app] Cannot re-open Flutter screen after multiple transitions between iOS native and Flutter未关闭bug
难度 4/5 3-5 天 新手友好度 35/100
-
Many samples use old Gradle, impossible to build on modern JDK可能已有人在做 @ericwindmill 于 664 天前认领。 未关闭bug
-
meta
难度 5/5 一周以上 新手友好度 25/100
-
[navigator2 quickstart] Create a navigator2 quickstart可能重新可做 @mranja 于 40 天前认领,目前没有进行中的 PR。 未关闭enhancement
难度 5/5 一周以上 新手友好度 25/100
-
enhancement
难度 4/5 3-5 天 新手友好度 25/100
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 60/100
hiddify/hiddify-app#2668 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
toyota-connected/emb_cli#358 ·
维护者通常 1 天内回复
-
area: import beta cluster: callers box improvements severity: minor status: confirmed type: bug
难度 2/5 1-3 小时 新手友好度 62/100
ibanner56/CallersCompendium#2366 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
ccch1mneyyy/dsh-Go#1777 ·
维护者通常 1 天内回复
-
area: mobile documentation good first issue
难度 2/5 1-3 小时 新手友好度 76/100
CommandLineCoding/Elephant#383 ·
维护者通常 1 天内回复