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.
2 Answers
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.
1 Comment
Munes
The flutter_phoenix library doesn't appear to work with the newer versions of Flutter, I tested this and the app does not restart.
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
Munes
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.