flutterdartflutter-getxflutter-routes

Flutter passing boolean argument in getx route


I have two getx controllers 1 register and 2 home. I need to pass a boolean argument to home to notify if the user is registering first time.

on registration controller

// here's how iam trying to pass an argument using route

  Get.offAllNamed('/home',arguments: true);

on home controller

  final _isNewUserRegistration = false.obs;
  bool get isNewUserRegistration => _isNewUserRegistration.value;  // bool variable to check if the user is newly registered

and on oninit of homecontroller i'm trying to assign the argument to _isNewUserRegistration.

   @override
   void onInit(){
    super.onInit();
   _isNewRegistration(Get.arguments);
   }

But I couldn't get the argument value from the previous controller. How can I get the value passed from the previous controller to the current controller.


Solution

  • try this

    Get.offAllNamed('/home',parameters: {"boolean":true});
    

    On Home Controller

    final _isNewUserRegistration = false.obs;
    
    
     @override
       void onInit(){
        super.onInit();
       _isNewRegistration(Get.parameters['boolean']);
       }
    

    or try also this

    final _isNewUserRegistration = Get.parameters['boolean']; // or with obs
    

    mention me if its working