skip to content

Hot Reload & Restart

Hot reload injects changed source into the running Dart VM and rebuilds widgets with State kept; hot restart resets it. Interviewers ask why an edit to initState or a static did not appear.

part ofFlutteroverview, primer and where to startread it →
on this pageshow

explore

questions

5

In Flutter, what is the difference between hot reload, hot restart and a full restart, and when do you need each?

level: juniorimportance: must knowfreq 80%

answer

  1. r versus R in flutter run
  2. state kept versus state lost
  3. main() and initState() not rerun
  4. native edits need a full restart
  5. debug mode only

basics

~20 s

Hot reload injects changed Dart code and rebuilds widgets while keeping state; hot restart reloads the code and reruns main(), losing state; a full restart rebuilds native code too and is needed after Kotlin, Swift or plugin changes.

solid answer

~40 s

Hot reload (`r` in `flutter run`) loads the changed Dart libraries into the running VM and rebuilds the widget tree, so `build` methods pick up the change while `State` objects, navigation, and global and static values survive; it does not rerun `main()` or `initState()`. Hot restart (`R`) loads the code and restarts the Flutter app from `main()`, discarding all Dart state, but it does not recompile or relaunch the native host. A full restart stops and relaunches the app and is required when native code changed, such as Kotlin, Swift or a plugin with platform code. All three are debug-mode tools; on the web, hot reload is on by default since Flutter 3.35.

go deeper

for a junior

Recall which of the three keeps state, which reruns main(), and which one native code changes need.

for a middle

Explain why reloaded code shows only where a rebuild re-executes it, and why a hot restart is faster than a full restart.

for a senior

Show you pick the cheapest safe option per change and confirm suspicious behaviour with a hot restart before debugging it.

for a principal

Treat dev-loop speed as a team concern: keep start-up work and native changes contained so most edits stay hot-reloadable.

## Three ways to apply a change A Flutter app in **debug mode** can take a code change in three ways, each slower and more thorough than the last. Knowing which one a given edit needs is the first dev-loop question in most Flutter interviews. | | Hot reload | Hot restart | Full restart | |---|---|---|---| | `flutter run` terminal key | `r` | `R` | stop and run again | | What is reloaded | Changed Dart libraries | All Dart code | Dart and native code | | App state | **Kept** | Lost | Lost | | Reruns `main()` and `initState()` | No | Yes | Yes | | Rebuilds native (Kotlin, Swift, JS host) | No | No | Yes | | Relative cost | Fastest | Fast, no native build | Slowest, full build | ## Hot reload **Hot reload** injects the edited Dart source into the running Dart VM (or, on the web, the browser). After the VM swaps in the new versions of classes, functions and fields, the framework rebuilds the whole widget tree, so every `build` method runs with the new code. Everything else is left alone: the `State` objects, the navigation stack, scroll positions, text typed into fields, and the values of global and static variables. That is its value: you can tweak the padding on a screen five levels deep in the navigation stack without logging in and navigating there again. After a successful reload the console reports something like `Reloaded 1 of 448 libraries in 978ms.` It is also its limit. Code that is not re-executed by a rebuild, such as `main()`, `initState()` of already-created `State` objects, or the initializers of static and global variables, does not show its new behaviour. ## Hot restart **Hot restart** also loads the changed Dart code, then restarts the Flutter app from `main()`. All Dart state is thrown away: the widget tree, `State` objects, singletons and static fields are rebuilt from scratch. The native host process keeps running and is not recompiled, which is why a hot restart takes seconds rather than a full build. On the web, a hot restart can restart the app without a full page refresh. Use it when: - you changed `main()`, app start-up code or `initState()` and need it to run again; - you changed the initializer of a global or static field; - hot reload rejected the change, for example turning an `enum` into a class or changing a class's type parameters; - you want to confirm that a behaviour is real and not an artefact of reloaded state. ## Full restart A **full restart** means stopping the app and running it again. It is the only option when **native code** changed: Kotlin, Java, Swift or Objective-C in the host project, or a newly added plugin that brings its own platform code. It takes longer because the platform code is recompiled; on the web it also restarts the Dart development compiler. ## When each is available Hot reload and hot restart are debug-mode features, driven from `flutter run` in a terminal or from an editor's toolbar buttons (IDEs can also hot reload on save). Since Flutter 3.35 the web supports hot reload by default as well as hot restart. ## A quick decision guide 1. Changed a `build` method, a style, a string or a callback body: **hot reload**. 2. Changed start-up code, `initState`, a static initializer, or hot reload complained: **hot restart**. 3. Changed native code, native configuration or added a plugin with platform code: **full restart**.

  • Does a hot restart reset a Dart singleton that holds the logged-in user?
    Yes. A hot restart reruns `main()` in a fresh Dart state, so singletons, static fields and every `State` object are created again, and the user appears logged out unless the session is restored from storage. Hot reload, by contrast, keeps that singleton and its value.
  • You added a plugin with native code and hot restarted, but calls fail. Why?
    Hot restart only reloads Dart. The plugin's Kotlin or Swift side was never compiled into the running host, so its platform code is missing until you stop the app and run it again, which is a full restart.

Hot reload is changing a stage set during a play while the actors hold their positions; hot restart is sending the actors back to the first scene on the same stage; a full restart is rebuilding the theatre.

saying these in an interview costs you the question

  • Hot reload reruns main() so start-up code picks up the change.
  • Hot restart recompiles the Kotlin and Swift code too.
  • Hot reload resets the app state to avoid inconsistencies.
  • A new plugin with platform code works after a hot reload.
  • Hot reload also works in release builds on a device.
open as a page

In Flutter, why does a hot reload not show your change to main(), initState() or a static field's initializer?

level: middleimportance: must knowfreq 52%

basics

~20 s

Hot reload swaps in new code but only reruns build methods. main() and existing initState() calls already ran, and global and static fields keep their stored values as state, so those edits need a hot restart, a const field or a getter.

open as a page

Which Flutter code changes does hot reload reject or fail to apply, and what do you do instead for each?

level: middleimportance: should knowfreq 32%

basics

~20 s

Hot reload rejects turning an enum into a class or back and changing a class's generic type parameters, so hot restart. It cannot see native Kotlin or Swift edits or new platform plugins, which need a full restart, and it waits for compile errors to be fixed.

open as a page

A bug shows up in a Flutter debug session after several hot reloads but not after a hot restart; how do you tell a reload artefact from a real bug?

level: seniorimportance: should knowfreq 24%

basics

~20 s

Hot reload runs new code on state created by old code, so objects, statics and initState setup can be impossible combinations. Hot restart and reproduce from launch: if the bug is gone, it was a reload artefact; if it persists, it is real.

open as a page

How does hot reload work for a Flutter web app in Flutter 3.47, and how does it differ from mobile?

level: middleimportance: nice to knowfreq 20%

basics

~20 s

Since Flutter 3.35 hot reload is on by default for web debug builds, alongside hot restart. It loads updated DDC-compiled JavaScript into the page instead of a Dart VM, keeps state, and does not apply to Wasm or release builds.

open as a page