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

Time:06-09

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?

CodePudding user response:

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

  • Related