getx
getx copied to clipboard
return null in GetMiddleware not work as expect
Describe the bug
README says return null in GetMiddleware.redirectDelegate will makes no redirect. (see https://github.com/jonataslaw/getx#redirect ) With this feature, we can avoid entering the login page while we are already logged in. But I found it doesn't work.
**Reproduction code
Here's a example, I forked example_nav2 and just changed this line. https://github.com/wliu6v/getx/blob/master/example_nav2/lib/app/modules/root/views/drawer.dart#L55

Expected behavior & To Reproduce
As expected, with the EnsureNotAuthedMiddleware in place, clicking the Login item in the slidermenu should not enter the login page. But in fact, it does, and generates the following log
[GETX] Redirect to null
[GETX] "DashboardController" onDelete() called
Screenshots
Here's a screen record. The first login is OK, but the second login shouldn't exist.
https://user-images.githubusercontent.com/5987831/157031540-e4db5e91-fb70-476d-97ff-bfc8dc87a01e.mp4
Flutter Version:
Flutter (Channel stable, 2.8.1, on macOS 12.1 21C52 darwin-arm
Getx Version:
In my test, I forked the whole Getx project, use master branch to test it. So the version should be 5.0.0-beta.30
In my own project, I use 4.6.1.
Describe on which device you found the bug:
OnePlus 8 , Android version 10.
I can fixed it by add these lines in get_route_delegate : do nothing for _activePages when middleware return null.
I haven't fully tested this, so I won't create a pull request. But if anyone else wants to prevent enter new page by returning null in the middleware, they can try this immature solution.

interesting. What happens if you return the same parameter received rather null, using the master version?
@jonataslaw
seems nothing different between return null and return route in auth_middleware.dart -> EnsureNotAuthedMiddleware.
I get the similar problem, i can't get arguments passed from a page to another when i put the middleware. I see
[GETX] Redirect to null everytime and i believe it is the problem. I'm looking for the solution.
Same question
same here
Same.
same
any updates?
same
same
@jonataslaw any news?