Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attempting to hot reload Flutter app restarts whole app

Tags:

flutter

bloc

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?

like image 551
Lewis Cianci Avatar asked Aug 15 '19 21:08

Lewis Cianci


People also ask

What happens when hot reload in Flutter?

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.

What is hot reload and hot restart in Flutter?

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.

How to restart an app in flutter?

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.

Why is hot reload not working in flutter?

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.

Why does my Dart app keep restarting?

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.

How to fix ‘hot reload’ not working in Android Studio?

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.


1 Answers

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.

like image 98
Nehemie KOFFI Avatar answered Oct 20 '22 03:10

Nehemie KOFFI