Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"]);
like image 279
Jewel Rana Avatar asked Nov 19 '20 06:11

Jewel Rana


People also ask

Is GetX good for Flutter?

Obviously, both are used for state management. However, experienced Flutter devs do not recommend GetX.

How do I use Getstate instead of 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().


3 Answers

Step: 1 : Sending data

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

Step: 2 : Get data From first screen

var data = Get.arguments;
like image 93
Jewel Rana Avatar answered Nov 15 '22 10:11

Jewel Rana


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"}
]);
like image 34
Tejas Patel Avatar answered Nov 15 '22 09:11

Tejas Patel


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
        ],
      )
like image 34
Jewel Rana Avatar answered Nov 15 '22 11:11

Jewel Rana