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

Đang mở
#2,877 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

@Ersaoktaviannn đang làm issue này rồi.

Từ ngày 13/8/2026.

  • #2880 của @Ersaoktaviannn — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
dart
Lĩnh vực
desktop-dev

Hướng nghiên cứu

Bắt đầu bằng cách truy vết quá trình khởi tạo HomeViewModel trong HomeScreenContainer và hành vi của route HomeScreen thông qua go_router, đồng thời so sánh với hành vi rebuild trước #2788. Tái hiện luồng Windows bằng cách đặt một chuyến đi rồi quay về màn hình chính; được coi là hoàn tất khi chuyến đi mới xuất hiện mà không cần hot reload và cập nhật state liên quan đã được bao phủ hoặc xác minh.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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: [ ...
Ngôn ngữ chính
Dart
Star
19.3k
Fork
7.8k
Merge trung bình
1 ngày 18 giờ
Pull request đã merge (30 ngày)
4

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của flutter/samples

Tất cả issue của flutter/samples

Issue tương tự

Thêm issue về Dart

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.