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

Page does not change despite state changing #48

Closed
dan-leech opened this issue Jun 25, 2021 · 10 comments
Closed

Page does not change despite state changing #48

dan-leech opened this issue Jun 25, 2021 · 10 comments
Assignees
Labels
question Further information is requested

Comments

@dan-leech
Copy link

Describe the bug
The last page is frozen in page stack despite there is a new page should be.

I use _onGeneratePages this way:

[
if (flowState.input != null) NameForm(),
if (flowState.input == null && (flowState.medications?.isNotEmpty ?? false))
  SummaryPage(),
]

Flutter version is 2.2.2

I'm sure(I debugged and checked all things) that after state update only NameForm in the stack. But SummaryPage is still on the screen.
Might it be Navigator issue...

I'm trying downgrade now.
Might someone have the same issue?

@dan-leech
Copy link
Author

downgrade does not help.
Might Navigator thinks that one page == one another page?

@dan-leech
Copy link
Author

I've found the issue.

If I use MaterialPage all is ok. But pages do not want to switch if I use CustomMaterial page without animation or delay.

class CustomMaterialPage<T> extends Page<T> {
  const CustomMaterialPage({required this.child, LocalKey? key})
      : super(key: key);

  final Widget child;
  static const _transitionDuration = Duration(milliseconds: 50);

  @override
  Route<T> createRoute(BuildContext context) => PageRouteBuilder(
        settings: this,
        transitionDuration: _transitionDuration,
        reverseTransitionDuration: _transitionDuration,
        pageBuilder: (
          context,
          animation,
          secondaryAnimation,
        ) =>
            FadeTransition(opacity: animation, child: child),
      );
}

@felangel Any Ideas?
I guess that I use animation incorrect, but it works in general cases when pages go one by one. And it glitches on replace.

@felangel
Copy link
Owner

Hi @dan-leech 👋
Thanks for opening an issue!

Can you please share a link to a minimal reproduction sample? Thanks! 🙏

@felangel felangel self-assigned this Jun 29, 2021
@felangel felangel added the question Further information is requested label Jun 29, 2021
@dan-leech
Copy link
Author

@felangel Just try to use CustomMaterialPage instead MaterialPage in any OnGeneratePages

I solved this with rewriting MaterialPage because it does not use PageRouteBuilder. PageRouteBuilder glitches.

@remonh87
Copy link

remonh87 commented Jul 16, 2021

@felangel I have exactly the same issue as @dan-leech . I have created the a repo for you that shows the error I have encountered: https://github.com/remonh87/flowbuilder_issue_repo .

Also I have 2 scenarios that do work (one is exactly what Dan mentioned if you change to material page no issues).

I used the standard Flutter example for pageroutebuilder. Let me know if you need more.

@liPatrick
Copy link

I looked into @remonh87 repo and it turns out that the problem is not a flowbuilder issue but a Navigation2.0 issue. I replaced Flowbuilder with Navigation and reproduced the same problem (where the MaterialPage works but not a CustomPage). If you want to use a navigation bar, I would suggest just having a list of pages and selecting between them using setState when a bottom nav bar item is tapped. You can then add a flowbuilder widget within each page to control navigation.

@remonh87
Copy link

@liPatrick sorry for my super late reaction (for some reason missed your reply). The suggestion you proposed works great and is actually quite a nice one.

@felangel
Copy link
Owner

@remonh87 that's great to hear, thanks for sharing! Closing this for now since it doesn't appear there is any further action required. Let me know if you have any additional comments/questions and I'm happy to continue the conversation 👍

@ToniTornado
Copy link

I had the same problem (flow no longer updating) and came across this issue. Thanks for sharing your minimal example @remonh87.

So here is the deal: I tell you how to fix your CustomPage example and you find out and tell me why my fix works. 😉

To fix your CustomPage flow, all you need to do is add a key to at least one of the pages in your flow.

  static CustomPage<void> page() => const CustomPage<void>(
      name: 'page1',
      child: _Page1(),
      key: ValueKey('page1'), // <- This line is added
    );

That's it.

In my app I was cleaning up some code and among many other changes I removed a key from a MaterialPage. The flow has more than just two pages and the last step an alert that changed a parent flow. Reverting all my changes step by step lead to a tiny - and what I thought useless - key. Note: In my app I am using MaterialPages and it was not working. So maybe it is also a mystery to be solved why your MaterialPage example works...

My first thought was ok, there are only MaterialPage objects in the route list so for the rebuild to work we need keys to distinguish them. But why is one key enough for as it seems any number of pages?

@Boolin365
Copy link

I had the same problem too - thanks for the fix, @ToniTornado.

I would also be interested to know why this works as it does...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants