[compass_app] UI state never updates for the HomeScreen (regression after the implementation of #2788)

オープン
#2,877 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

@Ersaoktaviannn がすでに取り組んでいます。

2026年8月13日 から。

  • #2880 @Ersaoktaviannn による — オープン

評価

難易度
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:

  1. Book a new trip;
  2. Come back to a home screen;
  3. 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:

  1. User moves to the home route '/' or deeper;
  2. 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

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

flutter/samples のほかの issue

flutter/samples の issue をすべて見る

似ている issue

Dart の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。