getx
getx copied to clipboard
Arguments always return null in GetMiddleware. How to use it right way?
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
Get.arguments should be available in the redirect. Are you using the version 4 or 5?
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 :(
You can use the Get.arguments; method to get the data from the previous page.
@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?
@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