'flutter passing multiple data with getx

I want to Pass multiple data from one screen to another screen with Get package.

Get.to(Second(), arguments: ["First data", "Second data"]);


Solution 1:[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:[2]

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"}
]);

Solution 3:[3]

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 4:[4]

If you navigate screen through perticular screen name then do it like this

First you need to define list of pages in the GetMaterialApp() widget

GetMaterialApp(
  home: Home(),
  getPages: [
    GetPage(name: '/home', page: () => HomeView()),
    GetPage(name: '/second', page: () => Second()),
  ],
);

Then use it like below

Get.toNamed("/second", arguments: ["First data", "Second data"]);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Striped
Solution 2
Solution 3 geisterfurz007
Solution 4 Paresh Mangukiya