I need to track every routing between pages with its previous page. I created my own observer class and passed it on routingCallback in GetMaterialApp. But i found that Get.previous returns wrong value. When i tried to dig through the Routing class, i found that the value.previous is assigned with wrong value.
@override
void didPop(Route route, Route? previousRoute) {
super.didPop(route, previousRoute);
final currentRoute = _RouteData.ofRoute(route);
final newRoute = _RouteData.ofRoute(previousRoute);
if (currentRoute.isSnackbar) {
// Get.log("CLOSE SNACKBAR ${currentRoute.name}");
Get.log("CLOSE SNACKBAR");
} else if (currentRoute.isBottomSheet || currentRoute.isDialog) {
Get.log("CLOSE ${currentRoute.name}");
} else if (currentRoute.isGetPageRoute) {
Get.log("CLOSE TO ROUTE ${currentRoute.name}");
}
if (previousRoute != null) {
RouterReportManager.reportCurrentRoute(previousRoute);
}
// Here we use a 'inverse didPush set', meaning that we use
// previous route instead of 'route' because this is
// a 'inverse push'
_routeSend?.update((value) {
// Only PageRoute is allowed to change current value
if (previousRoute is PageRoute) {
value.current = _extractRouteName(previousRoute) ?? '';
value.previous = newRoute.name ?? ''; <-- isn't this supposed to be currentRoute.name?
} else if (value.previous.isNotEmpty) {
value.current = value.previous;
}
value.args = previousRoute?.settings.arguments;
value.route = previousRoute;
value.isBack = true;
value.removed = '';
value.isSnackbar = newRoute.isSnackbar;
value.isBottomSheet = newRoute.isBottomSheet;
value.isDialog = newRoute.isDialog;
});
// print('currentRoute.isDialog ${currentRoute.isDialog}');
routing?.call(_routeSend);
}
Let's say the app navigates from A to B, then go back to A. In this case, the previous page should be the B instead of A.
Is the Get.previous supposed to return that value? or it is just me who misunderstand about using routingCallback?
Here's the observer class i made :
class Middleware {
static observer(Routing routing) {
switch (routing.current) {
case FirstPage.routeName:
debugPrint('first page tracker from ${routing.previous}');
break;
case SecondPage.routeName:
debugPrint('second page tracker from ${routing.previous}');
break;
}
}
}
Thanks!
To Reproduce
Steps to reproduce the behavior:
Create two pages
Create an observer class
Pass the observer function to routingCallback in GetMaterialApp
The console show wrong Get.previous value
Expected behavior
The Get.previous should return the previous page.
Screenshots
If applicable, add screenshots to help explain your problem.
I need to track every routing between pages with its previous page. I created my own observer class and passed it on
routingCallback
inGetMaterialApp
. But i found thatGet.previous
returns wrong value. When i tried to dig through theRouting
class, i found that thevalue.previous
is assigned with wrong value.Let's say the app navigates from A to B, then go back to A. In this case, the previous page should be the B instead of A. Is the
Get.previous
supposed to return that value? or it is just me who misunderstand about usingroutingCallback
?Here's the observer class i made :
Thanks!
To Reproduce Steps to reproduce the behavior:
routingCallback
inGetMaterialApp
Get.previous
valueExpected behavior The
Get.previous
should return the previous page.Screenshots If applicable, add screenshots to help explain your problem.
Flutter Version: Flutter (Channel stable, 2.2.3)
Getx Version: GetX: ^4.3.8