[compass_app] UI state never updates for the HomeScreen (regression after the implementation of #2788)
Đá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:
- 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: [ ...
- 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
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của flutter/samples
-
[add-to-app] Cannot re-open Flutter screen after multiple transitions between iOS native and FlutterĐang mởbug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
-
Many samples use old Gradle, impossible to build on modern JDKCó thể đã có người làm @ericwindmill đã nhận 664 ngày trước. Đang mởbug
-
meta
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
-
[navigator2 quickstart] Create a navigator2 quickstartCó thể làm lại được @mranja đã nhận 40 ngày trước và không có pull request nào đang mở. Đang mởenhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
-
enhancement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
Tất cả issue của flutter/samples
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 60/100
hiddify/hiddify-app#2668 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
toyota-connected/emb_cli#358 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: import beta cluster: callers box improvements severity: minor status: confirmed type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
ibanner56/CallersCompendium#2366 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ccch1mneyyy/dsh-Go#1777 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: mobile documentation good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
CommandLineCoding/Elephant#383 ·
Maintainer thường phản hồi trong vòng 1 ngày