26

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

Get.to(Second(), arguments: ["First data", "Second data"]);
Kishan Viramgama
  • 893
  • 1
  • 11
  • 23
Jewel Rana
  • 2,397
  • 1
  • 19
  • 28

4 Answers4

33

Step: 1 : Sending data

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

Step: 2 : Get data From first screen

var data = Get.arguments;
Striped
  • 2,544
  • 3
  • 25
  • 31
Jewel Rana
  • 351
  • 2
  • 6
  • I 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? args = Get.arguments; bool get forSelection => args!["FOR_SELECTION"]!;` – Faizan Mubasher May 21 '21 at 10:49
  • Is there a way to use onGenerateRoute function, like in the documentation https://flutter.dev/docs/cookbook/navigation/navigate-with-arguments, but using getx? – Antonycx Nov 15 '21 at 23:09
25

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"}
]);
Tejas Patel
  • 372
  • 4
  • 6
17

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
        ],
      )
geisterfurz007
  • 5,292
  • 5
  • 33
  • 54
Jewel Rana
  • 2,397
  • 1
  • 19
  • 28
2

You can pass a String, a Map, a List, or even a class instance.

Get.toNamed("/example_page", arguments: {'arg1': 'val1', 'arg2': 'val2'};

On the next page:

final args = Get.arguments;
print(args); // output: {arg1:val1, arg2:val2}
            

More detail

zorro
  • 101
  • 1
  • 10