Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When the AppFlowData changes, every page in the stack is rebuilt (can I get around it?) #47

Open
LucaDillenburg opened this issue Jun 23, 2021 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@LucaDillenburg
Copy link

Describe the bug
This is probably more of a question than an actual bug. Every change I make to the AppFlowData causes every page that is in the stack to rebuild itself. The problem is that I need for a particular page (the homepage) to show some animations and perform an API call when it first loads, however, when the home page adds another page to the stack or the page added is popped, for example, the homepage is rebuilt, showing the animation again and calling the API once more.
This is not the same behavior as if you are using named routes in the MaterialApp. I want to know if this is the expected behavior and how (if possible) I can get around it.

To Reproduce
Steps to reproduce the behavior:

  1. Create two pages and a FlowBuilder that starts only with one of them
  2. On a button click on the first page, change the FlowData to add the other page to the stack
  3. When you click the button (or pop the second page for that matter) you will realize that the first page was rebuilt.

I made an example in this repository.

Expected behavior
I believe the expected behavior should be the same as if you were using Flutter's regular routes system (MaterialRoute with routes property): when a page is added or removed from the stack, the other pages are not rebuilt.

@felangel felangel self-assigned this Jun 23, 2021
@duan-daniel
Copy link

Ran into the same issue with your reproduction sample. Upon further testing, it seems that when there are multiple pages in the navigation stack, whenever context.flow<FlowState>().update() is called with a change to FlowState all the pages provided in onGeneratePages get rebuilt.

A workaround could be to modify your flow state so that the home page is not included in onGeneratePages after you navigate to a new page. For example, in your flow_navigation reproduction sample you can modify routes.dart accordingly:

onGeneratePages: (state, pages) => [
  if (!state.subpage)
    MaterialPage<void>(
      child: Home(),
    ),
  if (state.subpage)
    MaterialPage<void>(
      child: Subpage(),
    ),
],

This way, once context.flow<AppFlowData>().update((data) => data.copyWith(subpage: true)) is called Home will not be included in the onGeneratePages list and won't get rebuilt.

@omartinma
Copy link

omartinma commented Aug 2, 2021

I'm able to reproduce this on the onboarding example of this repo @felangel
You can see that if you are in welcome page and navigates to the next, this welcome page will be rebuilt

@felangel felangel added the bug Something isn't working label Aug 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants