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

Getx controller not save previous state when back to it's page

I am using getx on my project. On my page, I have a button. when I pressed my button I open a new page:

  GetBuilder<SearchHomeController>(
      init: controller,
      id: 'dic',
      initState: (_) {},
      builder: (_) {
        if (controller.alertTypes != null) {
          return SliverToBoxAdapter(
            child: DialogLauncher(
              context: context,
              title: "Not Founded",
              message: "Do you want to Add?",
              callback: () async {
                await Get.toNamed(Routes.ADDNEWVOCAB,);
                controller.addNewVocab();
              },
            ),
          );
        }

In my new page I have another button and when I press on this button I back to first page :

  ElevatedButton(
    onPressed: () {
      Get.offNamed(
        Routes.HOMESEARCH,
        arguments: AddNewVocabModel(
          name: nameCtl.text,
          phonetic: phoneticCtl.text,
          ukPrononce: ukPrononce.text,
          usPrononce: usPrononce.text,
          position: position.text,
          description: description.text,
        ),
      );
    },
    child: const Text("Submit"),

Why when I back to the first page GetBuilder<SearchHomeController>( called again and it did not save its previse state?

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

>Solution :

Get.offNamed(
        Routes.HOMESEARCH,
        arguments: AddNewVocabModel(
          name: nameCtl.text,
          phonetic: phoneticCtl.text,
          ukPrononce: ukPrononce.text,
          usPrononce: usPrononce.text,
          position: position.text,
          description: description.text,
        ),

replace this with

Get.back();

if you want the previous state to be same

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