I want to Pass multiple data from one screen to another screen with Get package.
Get.to(Second(), arguments: ["First data", "Second data"]);
Obviously, both are used for state management. However, experienced Flutter devs do not recommend GetX.
The Getx state manager is easier than using setState. You just need to add a ". obs" at the end of your variable, and wrap the widget you want to change within a Obx().
Step: 1 : Sending data
Get.to(Second(), arguments: ["First data", "Second data"]);
Step: 2 : Get data From first screen
var data = Get.arguments;
If you need to pass data with key and value in getx then try this
First Screen
Get.to(() => SecondScreen(), arguments: [
{"first": 'First data'},
{"second": 'Second data'}
]);
Second screen
class SecondScreenController extends GetxController {
dynamic argumentData = Get.arguments;
@override
void onInit() {
print(argumentData[0]['first']);
print(argumentData[1]['second']);
super.onInit();
}
}
Get.back() result
Get.to(() => SecondScreen(), arguments: [
{"first": 'First data'},
{"second": 'Second data'}
]).then((result) {
if (result[0]["backValue"] == "one") {
print("Result is coming");
}
});
Get.back(result: [
{"backValue": "one"}
]);
I found this solution.
First screen
Get.to(Second(), arguments: ["First data", "Second data"]);
Second screen
Declare variable (list)
var one = Get.arguments;
Set data
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("${one[0]}"), // first element set here
Text("${one[1]}"), // second element set here
],
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With