skip to Main Content

I’m using GetMaterialApp.router from getx as I have used it to handle navigation in my app, but surprisingly it does not provide the same set of parameters as MaterialApp.router.

Nevertheless, I added routes using getPages. I have been trying to access Query parameters but it does not work. I’m able to access Path parameters using Get.parameters but it does not work for Query params.

Here’s my code, and I intent to take test1 as query parameter, and I’m getting null;

 GetPage(
          name: '/:session/:test',
          page: () {
            return Scaffold(
              appBar: AppBar(title: Text('${Get.parameters['session']}')),
              body: Column(
                children: [
                  Text('${Get.parameters['test']}'),
                  Text('${Get.parameters['test1']}'),
                ],
              ),
            );
          },
        ),

I’m trying to open the app using a dynamic link and for path params it works fine but it does not seem to work for query params.

2

Answers


  1. Chosen as BEST ANSWER

    I started off by using GetMaterialApp.router as I had previously used MaterialApp.router to handle query parameters, when user taps on a link to open the app. This way I was able to read path parameters, but was getting null, when trying to access query parameters.

    After failing to find any solution, I decided to shift back to GetMaterialApp and see if it offers routing options just like the GetMaterialApp.router constructor, and with that my problem was solved.

    GetMaterialApp(
            initialRoute: '/',
            getPages: [
              GetPage(
                name: '/',
                page: () {
                  return const OdooAuthWrapper();
                },
              ),
              GetPage(
                  name: '/signup',
                  page: () {
                    return  AddNewPasswordPage(token: Get.parameters['token'],);
                  }),
            ],
            // home:  getPage(),
          ),
    
    

    GetMaterialApp.router has more complex routing configurations to offer, and for some it might make more sense to use it, but in my case GetMaterialApp was enough.


  2. According to the creator of Getx, Get.parameters and Get.arguments are ephermal and have to be assigned to a variable. Reference

    Read from query

    //Path  /:session/:test?param1=value1&param2=value2
    
    final queryParams = Get.parameters;
    final param1 = queryParams['param1'];
    final param2 = queryParams['param2'];
    

    Read from path

    //Path /session/param1/param2
    
     final param1 = Get.parameters['param1'];
     final param2 = Get.parameters['param2'];
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search