How to manage Flutter on boarding wizard navigation history management

Viewed 25

I have an onboarding wizard where users select different inputs and press back button and update value again. Now my requirement is suppose Im on wizard step 3 and close the app (remove from stack even) and reopen the app it will move user to directly on step 3. So that is done. But now if user press the back button it should be moved to step 2.

So how do i manage history for navigation to redirect user to the proper screen.

Eg.

I have the wizard as below.

Step1 => Step2 => Step3 => Step4

Im on Step3 and I killed the app or we can say removed from stack.

Now when I reopen the app it directly brings me to Step3 as I left from there.

so suppose now when user press the back button It should bring user to the Step2. And same again I press back button it will move user to the Step1.

So how to achieve this kind of situation.

1 Answers

You need to store a variable in Shared Preferences,

For Ex- You are on step 3 then shared this step in shred preference. Now if user reopen app then check last step store in shared preference if that is null or empty then open Step 1 page else open Saved Step Page.

Now if user press back button check whether user open that page from saved Step if yes then call Navigator.pushReplacementNamed(context,Routes.Step2); else call Navigator.pop(context);

For more details about Shared Preferences Click Here

Related