12

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

Get.to(Second(), arguments: ["First data", "Second data"]);
Jewel Rana
  • 1,614
  • 1
  • 15
  • 23

4 Answers4

13

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,477
  • 3
  • 24
  • 30
Jewel Rana
  • 141
  • 5
  • 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
11

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
  • 224
  • 3
  • 5
6

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
  • 4,398
  • 5
  • 34
  • 51
Jewel Rana
  • 1,614
  • 1
  • 15
  • 23
0

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"]);
Paresh Mangukiya
  • 37,512
  • 17
  • 201
  • 182