3

I am using the getx package in my application and there is something I am wondering about. Is it possible to reset all states of my app using getx? So it's kind of like a restart.

0

2 Answers 2

7
    Future<void> logoutUser() async {

    SharedPreferences prefs = await SharedPreferences.getInstance();
    prefs.clear(); //clearing my token data
    await Get.deleteAll(force: true); //deleting all controllers
    Phoenix.rebirth(Get.context!); // Restarting app
    Get.reset(); // resetting getx

  }

used flutter_phoenix library to restart the app. Deleted all GetX controllers using Get.deleteAll(force: true);

Works like a charm for me.

Sign up to request clarification or add additional context in comments.

1 Comment

The flutter_phoenix library doesn't appear to work with the newer versions of Flutter, I tested this and the app does not restart.
1

If you need to perform a full OS-level restart, you can use the "restart_app" plugin, which utilizes native APIs to restart the app. With this method, you won't have to worry about manually resetting states as the app restarts entirely from the beginning.

1 Comment

I don't like the way this works on iOS, it requires notifications to have been accepted by the user, as iOS attempts to show a notification to the user to re-open the app. GetX really needs to add a simpler way to reset state data in all controllers in memory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.