-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
StatefulWidget rebuilding unnecessarily after Navigator.push()/pop() #18366
Comments
I think it is similar to #11426 |
yeah, the same core issue as #11426 but this description is more helpful - it has nothing to do with tabs per se. in addition to the above mentioned problem of needlessly re-fetching and/or re-computing, you can't maintain a list's scroll position as described by those docs. if you're 100 cards deep, push to a card detail, and then pop, you're at the top of the list again. for those facing that problem, don't call ScrollController from InitState. instead, call it inside the build:
and then inside your stream/future builder:
|
I found flutter_gallery has the same problem |
it's basically working as intended. You should assume that https://flutter.io/search/?cx=007067728241810524621%3Agm6vraqlc8c&ie=UTF-8&hl=en&q=maintainstate might help to avoid build being called when a new route is added. |
But if a page has many images ,you can see that image blink as if render again. I use image cache |
@lishuhao what's the problem with using image cache? |
check this video |
Focus on the picture of the first page |
Thanks this really helped me save the scroll position of a long list when navigating to another screen and backing out of it. |
This is another dupe of #11655. |
@zoechi Hello, The home page has BottomNavigationBar, there are three sub-pages, now enter the second-level page(user Navigator.push()) from the third page. After returning back, the page becomes the first sub-page, not the original third page. How can I solve this problem? Please forgive my English |
Did not help me. I am having listview with multiple child listivew in it who has stream builder which gets the data from frirestore. Please help me with this. |
You can preserve scroll position using PageStorageKey property in ListView. |
@lishuhao did you resolve this problem? Please tell if so. |
I met the same problem, have you solved the problem我也遇到了相同的问题,请问您解决了吗? |
I use static variable to fix the problem. chang index when user switch tab. like this Global static variable homePage
|
Hi, I have same problem with a StatefulWidget, the widget rebuilds after Navigator.push()/pop(). |
same, but not a solution yet, it almost makes me mad |
maybe you can try it. home
if you change tab
my email address is we@jokerliang.cn that if you dont understand |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
In the example bellow, every time we call Navigator.push()/Navigator.pop() the widget is unnecessarily
rebuilding.
It only happens with a StatefulWidget. If we use a StatelessWidget the rebuild does not occurs.
This behavior is harmless with simple UI pages but can impact negatively when we have the widget body wrapped around by a FutureBuilder doing some expensive computation.
Steps to Reproduce
Code
Logs
analyze.txt
doctor.txt
run.txt
The text was updated successfully, but these errors were encountered: