In Flutter Getx, what is the difference between `Get.parameters` and `Get.arguments`?
Asked Answered
B

1

7

In Getx when navigating to a new page, you can pass data to the second page as 'arguments':

Get.toNamed('/second', arguments: {});

or as parameters

Get.toNamed('/second', parameters: {});

and in both cases, you can access this data using Get.arguments and Get.parameters accordingly.

So why are there two concepts if they achieve the same purpose?

Three differences I noticed:

1- parameters have to be of String type, and arguments can be of any type.

2- parameters get appended to the named route like so /second?parameter1=value1, arguments don't.

3- some classes in Getx can only accept arguments, not parameters for example:

RouteSettings can only take arguments although it requires a named route so it can theoretically accept parameters and append them after the route name.

Regards

Bandler answered 20/8, 2022 at 17:51 Comment(0)
E
5

Get.parameters

Will grab the value of query strings that are set by the parameters : {} part of the Get.toNamed method. Thus, the parameters defined will be displayed on the URL bar of a browser. This is commonly used on web development where you need to display some stuffs (like ids) and let the user change the value manually to get different data / view depending on what parameters available for filtering. That is why it appears in such format endpoint/?parameter1=value1

Get.arguments

In the other hand, will not display its values on the URL bar of a browser. This is commonly used in mobile / desktop development where query strings are not really necessary or when you don't want the user to be able to modify it directly in the runtime.

Extraordinary answered 2/9, 2022 at 20:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.