How to restart the app with flutter Android and iOS

Hi all, welcome back to my blog. And today lesson is about flutter again. I have a little problem when trying to resart the app directly from the app. So what I mean is I want to restart the app after users do something. Because if I don't do it, the app flow will be bad and the data that I want to refresh will be failed.

So in my use case in my app is I want to restart the app after user sign in or sign out in my app. The reason is I need to restart all of the previous state. That's the easy way I can do, and I have some problems with camera plugin.

The problem is happened only on android, so when you click sign in google/facebook, there'll be new page native from their sdk and making the app in inactive status. That'll will make camera bug, and it will make the app crash.

So for anticipate it I need to resart the app both android and iOS. Luckily there's plugin called phoniex to do it https://pub.dev/packages/flutter_phoenix and sadly it only works on iOS in my side because the camera issue I think the problem cannot be solved using this plugin.

So luckily for android we can do resart the app natively with this plugin https://pub.dev/packages/restart_app and the way I did is doing spesific logic for the platform like this

And for your information my app got disabled permission from facebook because the crash after the users sign in in my app using facebook platform, so the issue I got from facebook haha. Thanks for becoming QA in my app haha JK.

And finally to do it I put this function in my utils class and I call this everywhere, so It's very helpful to solve the annoying issue in my app.  Hopefully it could help you to tackle your own problem about resarting the flutte app. And I hope the plugin resart_app will support on iOS as well. Thanks for visiting my simple blog. And I have created new app called Age Life you can try ready you age advice there, it's fun to share with others people.

void restartApp(BuildContext context) {
if (Platform.isAndroid) {
Restart.restartApp();
} else {
Phoenix.rebirth(context);
}
}

Popular posts from this blog

Missing system image Android Studio solution

How to have ConstraintLayout inside ScrollView and ScrollView inside ConstraintLayout Android

Fixing Keyboard Hide When Reload UITableview iOS swift 5