2

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.

OneMore
  • 89
  • 1
  • 7

2 Answers2

4
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.

Saurav Prakash
  • 588
  • 1
  • 5
  • 26
0

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.

Hossein Yousefpour
  • 3,827
  • 3
  • 23
  • 35