Introduction
This is a very short chapter, but it contains valuable information that you will use all the time. When are running a Flutter app and you make code changes, you can tell your editor to reload them. That is the subject of this chapter.
Hot Reloads
In fact, one of the great things about Dart is its ability to hot reload code.
The Official Documentation Says:
Flutter’s hot reload feature helps you quickly and easily experiment, build UIs, add features, and fix bugs. Hot reload works by injecting updated source code files into the running Dart Virtual Machine (VM). After the VM updates classes with the new versions of fields and functions, the Flutter framework automatically rebuilds the widget tree, allowing you to quickly view the effects of your changes.
Two Options
After you have made your code changes, you have two options in regard to reloading:
- Hot restarting.
- Hot reloading.
Hot Restarting
This loads your changed code into the Dart VM and restarts the application. This is the safest thing to do and doesn’t take long.
Hot Reloading
If you want to load your changed code into the Dart VM but you don’t want to restart the application or change its state, you can do this. The result might be different behavior vs a hot restart. Just remember your code changes may not work with the existing state.
Android Studio
Both hot restart and hot reload are available in the run/debug tool windows.
Visual Studio Code
Both hot restart and hot reload are available in the Command Palette.
Command-Line
If you are using ‘flutter run’ to run the app from the command line, you can use the key ‘R’ to hot restart and the key ‘r’ to hot reload.