Skip to content
New issue

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

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

Already on GitHub? # to your account

tutorials 010 012 014 view rebuild many times #17

Closed
guoyongsheng opened this issue Jul 22, 2019 · 3 comments
Closed

tutorials 010 012 014 view rebuild many times #17

guoyongsheng opened this issue Jul 22, 2019 · 3 comments

Comments

@guoyongsheng
Copy link

LoginView push to HomeView, HomeView push to PostView, loginView will rebuild

@FilledStacks
Copy link
Owner

FilledStacks commented Jul 22, 2019

Remove the '/' from the login. That was my mistake. Adding a / will construct the views based on the deepling protocal so it'll create all views infront of that as well.

So use 'login' instead of '/#'

@guoyongsheng
Copy link
Author

login----> home : login will build
home ---> login : login will build
login build many times, i want login build once

@FilledStacks
Copy link
Owner

Oh you mean that. That's just how Flutter works. It rebuilds for major events like that. Navigation will rebuild, opening the keyboard will rebuild, locking the screen will rebuild, going into background will rebuild, poping a route from navigation will rebuild, etc. Since the UI is a function of state this should be kept in mind because you'll have to write your code to always return the same result giving a state and be able to be executed 100's of times without side effects. Your page will never be rebuilt once ONLY , unless you navigate there, never call set state and never navigate away.

Something you shouldn't do below!!

If you want to do this you can hack the Flutter approach and use a stateless widget for every widget, keep a local widget with your view that's built once and then only construct that when it's null.

Like in this answer. But that is directly fighting against the Flutter patterns. I've never had to do this. Can you tell me the reason you don't want it to rebuild, maybe I can help you solve your root problem

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants