The behavior of GetObserver.didPop may have caused a bug
Describe the bug In some cases, Get.to does not take effect because page == currentRoute.
if (preventDuplicates && page == currentRoute) {
return null;
}
Reproduction: There is a dialog(Get.dialog) in the page. After clicking it, you navigate to Page A, but the dialog is not dismissed. In Page A, clicking a button triggers a bottom sheet. After dismissing the bottom sheet, you use Get.back() to return to dialog page. At this point, if you try to Get.to Page A again, the bug mentioned above will occur.
I found the relevant code, but I’m not sure whether this behavior is by design or actually a bug.
// route_observer.dart
@override
void didPop(Route route, Route? previousRoute) {
super.didPop(route, previousRoute);
final currentRoute = _RouteData.ofRoute(route);
final newRoute = _RouteData.ofRoute(previousRoute);
// some other codes
// 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 ?? '';
} else if (value.previous.isNotEmpty) {
value.current = value.previous;
}
});
}
In this piece of code, the newRoute variable is constructed from previousRoute. This means that newRoute and previousRoute essentially point to the same route. However, when setting value.current and value.previous, the code uses previousRoute and newRoute, which results in both value.current and value.previous have same name string. Is this behavior by design, or a mistake
In addition, value.current is only assigned when the condition value.previous.isNotEmpty is met.
These factors together cause the bug described above.
Flutter Version: 3.24.4
Getx Version: 4.6.1
Describe on which device you found the bug: any devices.