flutter passing multiple data with getx
19,764
Solution 1
Step: 1 : Sending data
Get.to(Second(), arguments: ["First data", "Second data"]);
Step: 2 : Get data From first screen
var data = Get.arguments;
Solution 2
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
],
)
Solution 3
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"}
]);
Author by
Jewel Rana
Hello and welcome to my profile. My name is Jewel Rana. I have 2 year’s experience in Android application development(Java) and 1+ Year experience in Flutter application development. During this journey I have developed mostly mobile applications like eCommerce, Food delivery app , Rideshare(modified codecanyon project). I have experience working on Android, Java, XML, Kotlin(basic), Dart, Flutter.
Updated on June 04, 2022Comments
-
Jewel Rana about 2 years
I want to Pass multiple data from one screen to another screen with Get package.
Get.to(Second(), arguments: ["First data", "Second data"]);
-
Faizan Mubasher about 3 yearsI am passing data like:
onPressed: () => Get.to(() => GendersPage(), arguments: {"FOR_SELECTION", true})
, but when I try to access argument as map, I get an error.final Map<String, bool>? args = Get.arguments; bool get forSelection => args!["FOR_SELECTION"]!;
-
carrasc0 over 2 yearsWhat about the case of ''Get.back();'' To send data back? Any ideas? I'm struggling with it hardly
-
Antonycx over 2 yearsIs there a way to use onGenerateRoute function, like in the documentation flutter.dev/docs/cookbook/navigation/navigate-with-arguments, but using getx?
-
Tejas Patel over 2 years@carrasc0 I edited the answer please check.