Home > Mobile >  Flutter return a screen that has previous screens pushed into its navigator
Flutter return a screen that has previous screens pushed into its navigator

Time:01-20

I have the following situation:

I have an onboarding user flow that consists of lets say 5 screens where the user provides some personal details on each screen, the details are persisted into the database after each screen and then the user is taken into the home screen.

Desired behaviour: When the user provides detalis until e.g. screen 3/5 and then exits the application, the flow should resume from screen 3/5, with the posibility to return back to screens 1 or 2 to change the already provided details.

I couldn’t find anything in the navigator documentation that would help me, and if you could provide at least a documentation lead for this edge case it would be amazing.

Basically I need to restore the stack of screens “in the background” when the user re enters the app and “show” the stack from the screen i/n (where i is the first screen where the user did not provide details in the last session) with the possibility to navigate back in the stack to the screens before i even if those screens were not shown to the user in the current session. Or even more simply put, I need to restore a stack of screens in a new app session and show the user a screen from any position of the navigator stack based on data persisted on a db. Thanks!

CodePudding user response:

You can use PageView widget from flutter for your onboarding process, that way you can save on which page user was by the database entries, and you can directly jump on the specific page you want by the index. That way you don't have to worry about navigating through the screens.

Here's the link for PageView Widget implementation: https://www.geeksforgeeks.org/pageview-widget-in-flutter/

CodePudding user response:

Well I think first you need to store the data the user already entered and the screen number he was on. You can use something simple as shared_preferences.

Then you have to use routes to navigate to a specific screen.

  • Related