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
I started off by using
GetMaterialApp.router
as I had previously usedMaterialApp.router
to handlequery
parameters, when user taps on a link to open the app. This way I was able to readpath
parameters, but was gettingnull
, when trying to accessquery
parameters.After failing to find any solution, I decided to shift back to
GetMaterialApp
and see if it offers routing options just like theGetMaterialApp.router
constructor, and with that my problem was solved.GetMaterialApp.router
has more complex routing configurations to offer, and for some it might make more sense to use it, but in my caseGetMaterialApp
was enough.According to the creator of Getx,
Get.parameters
andGet.arguments
are ephermal and have to be assigned to a variable. Reference