Flutter Lesson 5 of 83 2 min read
Hot Reload vs Hot Restart in Flutter
Learn how hot reload and hot restart work in Flutter, what each one keeps and resets, and when you need a full restart.
On this page
Hot reload is why building in Flutter feels quick. You save a file and the running app changes in under a second, without losing where you were.
The three ways to see a change #
| Hot reload | Hot restart | Full restart | |
|---|---|---|---|
| Terminal key | r | R | q, then flutter run |
| Time | Under a second | A few seconds | Much longer |
| Keeps app state | Yes | No | No |
Runs main() again | No | Yes | Yes |
| Picks up native changes | No | No | Yes |
In VS Code and Android Studio, saving a file triggers a hot reload.
Hot reload #
Flutter injects your changed code into the running app and calls build again. Variables keep their values, so you stay on the same screen with the same data. It is ideal for layout, colours, text and logic inside build methods.
Hot restart #
The Dart code starts again from main(). All state is lost, but nothing native is rebuilt, so it is still fast.
When hot reload is not enough #
Hot reload re-runs build. It does not re-run code that already ran. Hot restart after changing:
main()or other start-up codeinitState()- initial values of global variables and
staticfields - an
enum, or the generic types of a class - a widget from
StatelessWidgettoStatefulWidget, or back
Do a full stop and run after changing:
- native code in
android/orios/ - adding a plugin that contains native code
- permissions, app icon or other native configuration
A quick rule: saved and nothing changed? Hot restart. Still nothing? Full restart.
See it for yourself #
Run the counter app, tap the button a few times, and then:
- Change the app bar title and save. The title changes and the count stays.
- Change
int _count = 0;toint _count = 100;and save. Nothing happens, because that line already ran. - Press
Rfor a hot restart. Now the count shows 100.
Things to know #
- Hot reload works only in debug mode. Profile and release builds are compiled ahead of time.
- If your code has a compile error, the reload is rejected and the app keeps running the old code. Fix the error and save again.
- State kept by hot reload can hide bugs in start-up logic. Hot restart now and then to check a clean start.
Try it yourself #
Find one change that hot reload applies and one that needs a hot restart, other than the ones above.