How to do complete app restart on button tap flutter.

 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:-


In your project wrap your whole app with the stateful widget. and when you want to restart your app rebuild that stateful widget with the child that possesses the different key.

The explanation image is here:-


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.



For more information on packages, widgets, and solutions take dive into the FlutterStuff.







Post a Comment

Previous Post Next Post

Contact Form