Flutter : finish all the screen/activity (for android/iOS both)

Issue

How can I finish all the activity/screen in Flutter.

I want it for Android and iOS.

Is there any way to same like finishAffinity() in Android we do.

Example:

A -> B -> C -> D -> Force Logout -> Open Login Screen and close all previous screen.

Solution

you can use this:

Navigator.pushAndRemoveUntil(context, yourRouteToLogin, (route) => false);

or if you have named routes:

  Navigator.pushNamedAndRemoveUntil(
      context, yourRouteName, (Route<dynamic> route) => false);

Answered By – BosS

Answer Checked By – Willingham (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *