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?
One of the popular features in Flutter is hot reload. It helps create UI, resolve errors, experiment, and add additional features as a developer. Injecting the latest source code into the virtual machine executes a hot reload. Dart VM reloads libraries with new code and updates sessions with the new functions.
Hot Reload allows us to see the reflected change after bug fixes, building User interfaces and even adding certain features to the app without running your application afresh over and over again. Hot restart destroys the preserved State value and set them to their default.
If you are working in the command prompt using flutter run enter ‘r’ to run. A hot restart has a slightly different functionality as compared to a hot reload. It is faster as compared to the full restart function. It destroys the preserved states of our app, and the code gets fully compiled again and starts from the default state.
Hot reload won’t work when generic type declarations are modified. For example, the following won’t work: If you’ve changed native code (such as Kotlin, Java, Swift, or Objective-C), you must perform a full restart (stop and restart the app) to see the changes take effect. Flutter’s stateful hot reload preserves the state of your app.
In some cases, small changes to the Dart code enable you to continue using hot reload for your app. In other cases, a hot restart, or a full restart is needed. Hot reload can break when the app is killed. For example, if the app was in the background for too long.
Restart the android studio (IDE). Now the ‘Hot Reload’ button will be enabled. Save All option is also used instead of Hot Reload button. (Ctrl + S or File Save All) Method #3: Make sure your application is open and not closed by you after running.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With