mesh
mesh

Reputation: 184

Flutter Getx arguments is always returning null

I am using Getx package in flutter to pass data to another page. But I am getting null data from the page.

this is my code to get.to

Get.to(xreadArticlePage(),transition: Transition.rightToLeft, arguments: 'dataExample');

this my code to get data from previous page. data is my data variable. xreadArticlePage is my page to get data.

Text(data.toString()),

this is to get previous page data. it has a to string because see the data without error for now

class xreadArticlePage extends StatelessWidget {
  @override
  var data = Get.arguments;
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                InkWell(
                    onTap: () {
                      Get.back();
                    },
                    child: Icon(Icons.arrow_back_ios)),
                Icon(Icons.abc_outlined),
              ],
            ),
          ),
          Expanded(
            child: SingleChildScrollView(
              physics: BouncingScrollPhysics(
                  parent: AlwaysScrollableScrollPhysics()),
              child: Container(
                child: FutureBuilder<List<dynamic>>(
                    future: fetch1WpPosts(),
                    builder: (context, snapshot) {
                      if (snapshot.hasData) {
                        return Padding(
                          padding: const EdgeInsets.all(8.0),
                          child: Column(
                            children: [
                              Text(
                                snapshot.data![0]["title"],
                                style: TextStyle(
                                    fontSize: 25, fontWeight: FontWeight.bold),
                              ),
                              SizedBox(
                                height: 10,
                              ),
                              Image.network(
                                  snapshot.data![0]["featured_image_large"]),
                              SizedBox(
                                height: 5,
                              ),
                              Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [
                                  Text(
                                    snapshot.data![0]["date"],
                                  ),
                                  Text(data.toString()),
                                ],
                              ),
                              Html(data: snapshot.data![0]["content"]),
                            ],
                          ),
                        );
                      }
                      return CircularProgressIndicator();
                    }),
              ),
            ),
          ),
        ],
      ),
    );
  }
}

Upvotes: 0

Views: 707

Answers (1)

Vikash Tiwari
Vikash Tiwari

Reputation: 161

Use below code:

Get.toNamed(Routes.ADD_ADDRESS_SCREEN, arguments: {
    'address': 'abc',
    'city': 'xyz',
});

Upvotes: 1

Related Questions