Hot restart in Flutter: when and when not?

Issue

could someone explain me the hot reload and hor restart and when i don’t have to do it (like changes in code that needs to perform a rebuild) and when i surely can. Both in Flutter web and mobile when debugging if i’m not sure that the changes i’ve made, affected the result, i close all and make a rebuild of the project… some insight in these two mode of “rapid-build” would make me more confident in what button i click during debug 😉

IDE: Android Studio 3.5.1

Solution

This if from the official documentation of Flutter for Android Studio and IntelliJ.

Hot Reload vs. Hot Restart

Hot reload works by injecting updated source code files into the running Dart VM (Virtual Machine). This includes not only adding new classes, but also adding methods and fields to existing classes, and changing existing functions. A few types of code changes cannot be hot reloaded though:

  • Global variable initializers

  • Static field initializers

  • The main() method of the app

For these changes you can fully restart your application, without having to end your debugging session.

From: https://flutter.dev/docs/development/tools/android-studio#hot-reload-vs-hot-restart

And here goes another explanation.

Hot Reload:

Hot reload feature quickly compile the newly added code in our file and sent the code to Dart Virtual Machine. After done updating the Code Dart Virtual Machine update the app UI with widgets. Hot Reload takes less time then Hot restart. There is also a draw back in Hot Reload, If you are using States in your application then Hot Reload preservers the States so they will not update on Hot Reload our set to their default values.

Hot restart:

Hot restart is much different than hot reload. In Hot restart it destroys the preserves State value and set them to their default. So if you are using States value in your application then After every hot restart the developer gets fully compiled application and all the states will set to their defaults. The app widget tree is completely rebuilt with new typed code. Hot Restart takes much higher time than Hot reload.

I got this explanation from: https://flutter-examples.com/difference-between-hot-reload-and-hot-restart-in-flutter-dart/

Answered By – André Junior

Answer Checked By – Robin (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *