15

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?

Lewis Cianci
  • 926
  • 1
  • 13
  • 38

1 Answers1

12

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.

Nehemie KOFFI
  • 1,159
  • 12
  • 11
  • Please phrase this as an explained conditional answer, in order to avoid the impression of asking a clarification question instead of answering (for which a comment should be used instead of an answer, compare https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead ). For example like "If your problem is ... then the solution is to .... because .... ." – Yunnosch Aug 01 '21 at 19:48
  • Works to me, i commented the navigatorKey on my main. Thank you – Gabriel Almeida Oct 13 '21 at 19:48