Using GetX with Flutter, I pass data between parent controller/screen to its child controller/screen using Get.arguments.
The issue is that when doing a hot-reload while working on a child Get.arguments, the parent gets re-instantiated with the arguments of the current controller/screen.
This issue is described here.
Is that a bug, or something that can't be avoided?
I use the Get.arguments in the controllers but still experiencing this issue...
Any suggestions?
CodePudding user response:
since Get.arguments
get it's value from the previous page, using it directly in your code will normally throw an error saying that it's null on hot reload/restart because it update the state
try saving Get.arguments first in a dynamic variable then use that varibale in your code
CodePudding user response:
You need to pass the arguments while navigating from the 1 screen to second like:
onTap: () {
Get.toNamed(screen2, arguments: ['ApplicationDemo']);
},
On the 2nd screen/controller, store the arguments in a variable like:
var a = Get.arguments;
Then use it like:
Text(a[0].toString() " " a[1].toString())
,
Alternatively, you can access it directly like:
Text(Get.arguments[0].toString() " " Get.arguments[1].toString())
;