OneMore
OneMore

Reputation: 99

How Can I Restart My Flutter App With Getx

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.

Upvotes: 3

Views: 4225

Answers (2)

Saurav Prakash
Saurav Prakash

Reputation: 654

    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.

Upvotes: 6

Hossein Yousefpour
Hossein Yousefpour

Reputation: 4953

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.

Upvotes: 1

Related Questions