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

Losing state on hot reload or otherwise triggered rebuild of entire app #193

Closed
slovnicki opened this issue Apr 16, 2021 · 13 comments
Closed
Labels
documentation Improvements or additions to documentation help Help and advice with usage

Comments

@slovnicki
Copy link
Owner

This issue is quite common. We should also add it to documentation as a tip.

@slovnicki slovnicki added bug Something isn't working documentation Improvements or additions to documentation help Help and advice with usage labels Apr 16, 2021
@slovnicki
Copy link
Owner Author

The solution is to move your BeamerRouterDelegate to a final variable outside build.

class MyApp extends StatelessWidget {
  final _routerDelegate = BeamerRouterDelegate(
    locationBuilder: ...
  );

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routeInformationParser: BeamerRouteInformationParser(),
      routerDelegate: _routerDelegate,
      ...
    );
  }
}

@slovnicki slovnicki pinned this issue Apr 21, 2021
@slovnicki slovnicki changed the title Redirect to initial path on hot reload or otherwise triggered rebuild of entire app Losing state on hot reload or otherwise triggered rebuild of entire app Apr 21, 2021
@lam-nv
Copy link

lam-nv commented Apr 26, 2021

Hi @slovnicki

In your opinion, is it okay if I want to add more locations at runtime, like enabling some features by activating an option in the settings?

I also encountered the same issue with you, even tested with example from beamer packages.

@slovnicki
Copy link
Owner Author

In your opinion, is it okay if I want to add more locations at runtime, like enabling some features by activating an option in the settings?

Sorry for late response @lam-nv, haven't notice this here. Yes, I think this should be fine.

@slovnicki
Copy link
Owner Author

Beware that #193 (comment) will not help if you're on web and flutter >2.0.6 because of flutter/flutter#79241

@slovnicki slovnicki removed the bug Something isn't working label May 23, 2021
@oyont

This comment has been minimized.

@slovnicki
Copy link
Owner Author

Hi @oyont
Could this be because you're using flutter version >2.0.6 as pointed out in this comment above?

@oyont
Copy link

oyont commented Jun 24, 2021

My flutter version is 2.2.0 but I'm running the app on web. It's happening on mobile too

@slovnicki
Copy link
Owner Author

This is in README so I'll close

@okelloEnos
Copy link

Just curious about this issue of losing state on rebuild :

  1. I experienced the same issue and resolved it using the comment #193(comment) in flutter 2.5.0.
  2. Then reading down the thread this comment from you to @oyont

Conclusion
Why do you suggest that this issue is experienced because @oyont is using flutter version >2.0.6 ??.... kindly can you suggest a way forward

@slovnicki
Copy link
Owner Author

Hi @okelloEnos
I think we can ignore that old comment about Flutter v2.0.6, but if I remember correctly, there was a time where some 2.0.X version did not lose state even when delegate was created inside build. And as I recall, this was an accidental Flutter feature which never occurred again 🙂

@tomasweigenast
Copy link

Can be this thread reopened? I've the same issue but moving BeamerDelegate to a final property does not work

@vrenan
Copy link

vrenan commented Nov 11, 2022

I'm also have this same issue

@slovnicki slovnicki unpinned this issue Apr 10, 2023
@holland-hng
Copy link

same issue :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation help Help and advice with usage
Projects
None yet
Development

No branches or pull requests

7 participants