felangel / flow_builder

Flutter Flows made easy! A Flutter package which simplifies navigation flows with a flexible, declarative API.
https://pub.dev/packages/flow_builder
MIT License
389 stars 63 forks source link

How to recover Profile example value to rebuild Page Widget #52

Closed tinoper closed 2 years ago

tinoper commented 3 years ago

Question

In Profile Flow Builder example, how can I check if age field have a previous value before type a new one?

To Reproduce Steps to reproduce the behavior:

  1. Profile Example.
  2. Fill Name field
  3. Click on 'Continue'
  4. Fill Age field
  5. Click on 'Continue'
  6. Fill Weight
  7. Click on 'Back Button '
  8. You can see Age field with Age typed on step 3
  9. Click on 'Back Button '
  10. You can see Named field with Name typed on step 1
  11. Click on 'Continue'
  12. Age field is empty as we are for the first time

Expected behavior I would expect to have the Age typed on step 3.

Screenshots image image image image image image

Logs Run flutter analyze and attach any output of that command below. If there are any analysis errors, try resolving them before filing this issue.

Paste the output of running flutter doctor -v here.

Additional context Maybe I can solve this recording to a local storage but I would like to be sure the solution doesn´t have an answer to this issue. Let me know if you need more information

duan-daniel commented 2 years ago

After further debugging, it seems that when the back button is pressed (and the top page of the navigation stack is popped), all state changes to the flow state made by the most recently popped page are discarded as well.

To reproduce this behavior, keep track of the value of context.flow<Profile>().state in each form's build method. Notice that whenever you navigate back from ProfileAgeForm to ProfileNameForm, the state gets reset to Profile(null, null, null), indicating that the previous changes to the flow state were discarded.

A solution could be to add a leading BackButton widget to the AppBar that updates the state with the new user inputted values and modify onGenerateProfilePages to show only one page in the navigation stack at all times.

felangel commented 2 years ago

Closing for now since there is no actionable next step. Feel free to comment with any follow-up questions and I'm happy to continue the conversation 👍