I'm working on a Flutter app and I've noticed that whenever I save my app to see the updated changes, my entire app reloads. I would expect the page that I have open to hot reload with my new changes on it.
I think that the way my widget tree is organised could have an effect on this. My entire app is wrapped in a widget that runs at startup that initialises to a ServicesLoadingState. Then, after the services have finished starting up (in the BLoC), it yields a ServicesReadyState and then all my widgets are drawn. I think when I hot reload, the state of the topmost widget switches back to ServicesLoadingState, reloads the services, and shows me the behaviour I'm experiencing.
I've tried googling "flutter hot reload restarts app" but I haven't found any good tips on how to prevent this. How can I stop hot reload from restarting the entire app?
Can you check if you are using a global navigatorKey in your MaterialApp ?
I faced the same issue and I found that it was due to navigatorKey in my MaterialApp.
So when I'm in dev mode, I comment the navigatorKey property.
Related
I have a problem with my Here Maps Navigation. I can start the navigation on my flutter app but every time I open another page on the app and come back to the navigation page, it restarts the navigation. It tries to get the current location again, takes a lot of time to do that, and shows the default "invalid" map page. I want the navigation to save it's current state even if I change the view to another page on my app and come back to navigating. Is there a way to do this? Am I missing something here?
I finally found a way to solve it by saving the state of my Flutter pages. I used the PageView widget for the main.dart's scaffold body and AutomaticKeepAliveClientMixin on the pages I wanted to save the states of. You can check this YouTube video for how to implement this: https://www.youtube.com/watch?v=fGe45NikVqE
I am trying to use easy_localization in my app and my state management in bloc. Everything working fine till I change the language. It is not changing all texts I need. It is changing half of the texts and stopping. It is only changing after hot reload. I have tried to rebuild bloc and it did not help me.
I'm making an app with a BottomNavigationBar with 5 different screens, each of them has a web view. The problem is that everytime I come back to a screen that was previously loaded, it reloads. I have tried using AutomaticKeepAliveClient from copy pasting this code but I doesn't seem to work. I'm new with Flutter so be precise please, thank you.
AutomaticKeepAliveClient is mainly used for keeping a child alive in lazily rendered list views. In your case whenever you switch tabs your current page get disposed and new page materializes on top of it, that means each time when you switch tab a new page is created including all it's widgets.
So if you want to keep your previously loaded web views alive, you have to go with either PageView widget or use Stack widget to load your pages programmatically while the user clicks on a tab.
This is a detailed example about implementing your requirement using PageView widget . you can also find an example with Stack widget under that question.
When I comment on New Text ('41 ') and then I press HOT RELOAD but it doesn't change, I've pressed a lot it hasn't changed, then I press the RUN button then it works fine
Anyone got the same problem?
enter image description here
Make sure you are using a stateless or stateful widget, the hot reload/refresh only works when you are dealing with state.
If you just run your main class without any state Widget, you'll have to run the application each time that you want to test a new modification.
I have a page that presents chat messages and has the dates of a group of messages as a divider in my flutter app. The data is pulled from localDB and I am trying to make it refresh the data by polling the DB for updates, however everytime I rebuild the stream or even future it makes the screen flicker and it automatically scrolls to the top of the list. The code is too big for here so I have posted it here.
It uses a Stream builder that calls a widget with data it gets from the first stream and uses another streambuilder to build the messages. I am sure this has something to do with it, but have no idea how to change that or fix the flicker and scroll weirdness.
Hoping someone has some ideas of how to handle this better or fix the flickering.
What you could try is creating a "app state" for each page, for example:
Loading app state - which displays a Progress Indicator when you're polling from DB/server.
Success app state - this dismisses the Progress Indicator and just shows an empty container, displaying your data.
Failed app state - Displays an error icon of your choice.
Perhaps you could try this library, Flutter GetX , and I recommend this library because of how simple it is to use.
It has state management library, which saved me lots of time and code using streams and setState({}).