[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 の route の動作を追跡し、#2788 より前の再構築の挙動と比較します。旅行を予約してホームに戻ることで Windows のフローを再現します。完了条件は、hot reload なしで新しい旅行が表示され、関連する state update がカバーされるか検証されていることです。
索引モデルが 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時間
- マージ済み PR(30日)
- 4
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 1週間以上 初心者へのやさしさ 25/100
-
[navigator2 quickstart] Create a navigator2 quickstart再び着手できるかも @mranja が 40 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンenhancement
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
-
enhancement
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
flutter/samples の issue をすべて見る
似ている 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 日以内に返信