Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use GetX effectively in routing this page?

https://imgur.com/a/gHHoUyr — >
in flutter app I have this page with 4 tabs. I redeem an offer and automatically am navigated to tab 2nd. But this happens only the 1st time. The rest number of redeems doesn’t get me to next tab but I stay on the same page. How can i fix this error? How can it only navigate the 1st time and not everytime?
This is the code snippt :

onPressed: () async {
                      didRedeem = false;
                      print("After Click $didRedeem");

                      redemeOffer(id).then((value) {
                       // confetticontroller.play();
                        showDialog(
                            context: context,
                            builder: (BuildContext context) {
                              _timer = Timer(Duration(seconds: 2), () {
                                Navigator.of(context).pop();
                                Navigator.pop(context);
                              });
                              return AlertDialog(
                                content: Text(redemeResponseBody),
                              );
                            }).then((value) {
                          if (_timer.isActive) {
                            _timer.cancel();
                          }
                          Future.delayed(Duration(seconds: 1), () {
                            setState(() {
                              didRedeem = true;
                            });

                            Get.to(() => OffersScreenPage(
                                  getIndex: 1,
                                  offers: false,
                                  collection: true,
                                  shopoffers: false,
                                  checkoffers: false,
                                ));
                          });
                        });
                      });
                    },

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If you are going to use routes/snackbars/dialogs/bottomsheets without context, GetX is excellent for you too, just see it:
Add "Get" before your MaterialApp, turning it into GetMaterialApp

GetMaterialApp( // Before: MaterialApp(
  home: MyHome(),
)

Navigate to a new screen: Get.to(NextScreen());

Navigate to new screen with name. See more details on named routes 

Get.toNamed('/details');

To close snackbars, dialogs, bottomsheets, or anything you would normally close with Navigator.pop(context);

Get.back();

To go to the next screen and no option to go back to the previous screen (for use in SplashScreens, login screens, etc.)

Get.off(NextScreen());

To go to the next screen and cancel all previous routes (useful in shopping carts, polls, and tests)

Get.offAll(NextScreen());

Noticed that you didn’t have to use context to do any of these things? That’s one of the biggest advantages of using Get route management. With this, you can execute all these methods from within your controller class, without worries.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading