How to do complete app restart on button tap flutter:
Today we learned about complete app restart on button tap.
In debug mode, we do complete app restart with the hot restart.
but now we do complete app restart in production mode
why do we need to complete app restart on button tap?
In some cases, we want to reload the complete app state, and then the app rerun from starting state.
There are two methods to do this process custom code and with the help dart package
I explain you to both methods in this blog.
1. Custom code method:-
2. With dart package:-
With the help of the dart package, we do this easily. In the dart packages library, there has a package named restart_app.
Installation:-
1. Add the package to pubspec.yaml dependency:
dependency:
restart_app:
2. Import the package where you want to use it:
import 'package:restart_app/restart_app.dart';
3. Call the restart app method where you want to use it:
onPressed: (){
Restart.restartapp(webOrigin: '[your main route] ').
}
For more info and detailed documents on this package view this package:-https://pub.dev/packages/restart_app.