getx
getx copied to clipboard
GetX 5 `GetMiddleware` almost all functions like `onPageBuilt` run twice
With nested navigation in example_nav2 example project, they will all run twice more.
Codes:
class AppPages {
AppPages._();
static const initial = Routes.home;
static final routes = [
GetPage(
middlewares: [MainMiddleware()],
preventDuplicates: true,
name: _Paths.home,
page: () => const HomeView(),
bindings: [
HomeBinding(),
],
title: null,
participatesInRootNavigator: true,
children: [
GetPage(
name: _Paths.dashboard,
page: () => const DashboardView(),
bindings: [
DashboardBinding(),
],
),
GetPage(
// middlewares: [
// //only enter this route when authed
// EnsureAuthMiddleware(),
// ],
name: _Paths.profile,
page: () => const ProfileView(),
title: 'Profile',
transition: Transition.size,
bindings: [ProfileBinding()],
),
GetPage(
name: _Paths.products,
page: () => const ProductsView(),
title: 'Products',
transition: Transition.cupertino,
showCupertinoParallax: true,
// participatesInRootNavigator: true,
bindings: [ProductsBinding(), ProductDetailsBinding()],
children: [
GetPage(
name: _Paths.settings,
page: () => const SettingsView(),
participatesInRootNavigator: true,
bindings: [
SettingsBinding(),
],
),
GetPage(
name: _Paths.productDetails,
transition: Transition.cupertino,
showCupertinoParallax: true,
page: () => const ProductDetailsView(),
participatesInRootNavigator: true,
bindings: const [],
// middlewares: [
// //only enter this route when authed
// EnsureAuthMiddleware(),
// ],
),
],
),
],
),
GetPage(
name: _Paths.settings,
page: () => const SettingsView(),
bindings: [
SettingsBinding(),
],
),
];
}
class MainMiddleware extends GetMiddleware {
@override
void onPageDispose() {
log('MainMiddleware onPageDispose');
super.onPageDispose();
}
@override
Widget onPageBuilt(Widget page) {
log('MainMiddleware onPageBuilt');
return super.onPageBuilt(page);
}
@override
GetPage? onPageCalled(GetPage? page) {
log('MainMiddleware onPageCalled');
return super.onPageCalled(page);
}
@override
List<R>? onBindingsStart<R>(List<R>? bindings) {
log('MainMiddleware onBindingsStart');
return super.onBindingsStart(bindings);
}
@override
GetPageBuilder? onPageBuildStart(GetPageBuilder? page) {
log('MainMiddleware onPageBuildStart');
return super.onPageBuildStart(page);
}
}
Screenshots:
And onPageDispose also run twice more!!!
This was introduced by Nested Bindings. When someone directly accesses a nested route in the browser, the parent's dependencies and middleware must be loaded. However, you're right, it should only start once, so I'm going to change the api to initialize Bindings only once.
This was introduced by Nested Bindings. When someone directly accesses a nested route in the browser, the parent's dependencies and middleware must be loaded.
However, you're right, it should only start once, so I'm going to change the api to initialize Bindings only once.
Thanks, so you mean that mb next version of GetX will change this?
Yeah, definitely.
Yeah, definitely.
Thanks for your help! Btw, could you please help with this issuse? Or mb there is something wrong with my nested routes. https://github.com/jonataslaw/getx/issues/3175