Dart Tutorial

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 reloadHot restartFull restart
Terminal keyrRq, then flutter run
TimeUnder a secondA few secondsMuch longer
Keeps app stateYesNoNo
Runs main() againNoYesYes
Picks up native changesNoNoYes

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 code
  • initState()
  • initial values of global variables and static fields
  • an enum, or the generic types of a class
  • a widget from StatelessWidget to StatefulWidget, or back

Do a full stop and run after changing:

  • native code in android/ or ios/
  • 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:

  1. Change the app bar title and save. The title changes and the count stays.
  2. Change int _count = 0; to int _count = 100; and save. Nothing happens, because that line already ran.
  3. Press R for 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.

Practise in the playground Updated by Santosh Adhikari