Reputation: 333
I pass data in getx routes but I don't understand how to get data on the next page.
List<UserModel> list = [];
var itemid = snapshot.data?.docs[index].id;
Get.toNamed(RoutesName.editAddNewHome_Screen,
arguments: [List[index],itemid ]);
I tried to get data on the next page but it showed an error.
List<dynamic> args = Get.arguments;
List<String> listData = args[0];
var myVariable = args[1];
error - The instance member 'args' can't be accessed in an initializer.
Upvotes: 0
Views: 351
Reputation: 66
With Getx Routing data are passed as map to an arguments
Get.toNamed(RoutesName.editAddNewHome_Screen,arguments: {"itemId: itemid ]);
In your case for retrieving the passed data using Get.arguments["itemId"], You can retrieve this data directly on your Widget, or get the value on initState this will solve error - The instance member 'args' can't be accessed in an initializer.
String itemId = “”;
@override
void initState() {
itemId= Get.arguments[“itemId”]??"”
super.initState();
}
But I would suggest making this data required on the screen and then passing this data on your route file
In your route file:
GetPage(name: RoutesName.editAddNewHome_Screen, page: () => EditAddNewHome_Screen(itemId: Get.arguments["itemId"] as String), ),
For in-depth understanding, check: https://github.com/jonataslaw/getx/blob/master/documentation/en_US/route_management.md
Upvotes: 1