getx icon indicating copy to clipboard operation
getx copied to clipboard

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

Open jin-chillo opened this issue 1 year ago • 5 comments

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

jin-chillo avatar Feb 13 '24 15:02 jin-chillo

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

jonataslaw avatar Feb 16 '24 19:02 jonataslaw

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 :(

jin-chillo avatar Feb 17 '24 10:02 jin-chillo

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

KeithGapusan avatar Feb 20 '24 14:02 KeithGapusan

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 avatar Apr 05 '24 08:04 phanil

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?

phanil avatar Jul 11 '24 08:07 phanil