Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arguments always return null in GetMiddleware. How to use it right way? #3037

Open
jin-chillo opened this issue Feb 13, 2024 · 5 comments
Open
Assignees

Comments

@jin-chillo
Copy link

Hello contributors thanks for contributing this project.

What I want

  • I want to move the page after logged in with arguments like below code attached.
// page1.dart

Get.toNamed('page2', arguments: {'a', 1});
// auth_middleware.dart

class AuthMiddleware extends GetMiddleware {
  Object? args;

  @override
  GetPage? onPageCalled(GetPage? page) {
    debugPrint('page?.arguments : ${page?.arguments}');  // return null

    args = page.arguments;
    return super.onPageCalled(page);
  }

  @override
  RouteSettings? redirect(String? route) {
    return Get.find<AuthService>().isAuthenticated
        ? null
        : RouteSettings(name: Routes.login, arguments: args);
  }
}

Issue

Arguments value passed by page1.dart is null in auth_middleware.dart

@jonataslaw
Copy link
Owner

Get.arguments should be available in the redirect.
Are you using the version 4 or 5?

@jin-chillo
Copy link
Author

Get.arguments should be available in the redirect. Are you using the version 4 or 5?

I'm using 4.6.6 version but It's still not working :(

@KeithGapusan
Copy link

You can use the Get.arguments; method to get the data from the previous page.

@phanil
Copy link

phanil commented Apr 5, 2024

image @KeithGapusan according to the code, it's just pass the name in the settings, without the arguments and by the way, Get.parameters is working well, but Get.arguments is always null

@phanil
Copy link

phanil commented Jul 11, 2024

image @KeithGapusan according to the code, it's just pass the name in the settings, without the arguments and by the way, Get.parameters is working well, but Get.arguments is always null

@jonataslaw could you help to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants