Sub topic 7
Triggering Reload and Restart: r, R, and IDE Buttons
Earlier chapters explained what hot reload and hot restart do. This chapter covers how you ask for them. Every trigger ends up sending the same request to the same running app, but each has its own habits and failure points.
This chapter assumes you can start an app with flutter run or from an IDE. It also assumes you know the difference between hot reload (keeps state) and hot restart (resets state).
What a Trigger Actually Does
When you trigger a reload, you are not talking to your app directly. You are talking to the flutter tool, which runs on your computer and stays connected to your app's Dart VM (the virtual machine that runs your Dart code in debug mode).
The tool does the following:
- It finds which source files changed since the last sync.
- It compiles those changes incrementally.
- It sends the result to the Dart VM.
- It asks the VM to either reload the code (hot reload) or restart the app's Dart code from
main(hot restart).
The terminal key, the IDE button, and the Unix signal described later all start at step 1. Only the way you ask differs.
Triggering from the Terminal
Start the app in debug mode:
flutter runWhile flutter run is active, the terminal reads single key presses. You do not need to press Enter. The most useful keys are:
| Key | Action |
|---|---|
| `r` | Hot reload |
| `R` | Hot restart |
| `h` | Print the list of available commands |
| `c` | Clear the terminal screen |
| `d` | Detach: leave the app running and stop the tool |
| `q` | Quit: stop the app and the tool |
The list of keys can vary with Flutter version and target platform, so press h to see exactly what your setup offers. Other keys toggle debugging aids, such as the widget inspector and debug paint. Those belong to later chapters on debugging.
What the Output Tells You
After you press r, you see a line similar to this:
Performing hot reload...
Reloaded 1 of 612 libraries in 284ms (compile: 31 ms, reload: 109 ms, reassemble: 98 ms).The first number is how many libraries (Dart files, roughly) had changes sent to the VM. If it says Reloaded 0 of 612 libraries, the tool found no changed files. That points to an unsaved file or an edit outside the project, covered in the troubleshooting chapter.
After you press R, the output looks like this:
Performing hot restart...
Restarted application in 1,204ms.A restart takes longer than a reload because the app's Dart code starts over from main.
Common Terminal Mistakes
Two more things to watch:
- If you pipe or redirect the input of
flutter run, it has no keyboard to read. Use the signal method below instead. - If the terminal shows a compile error after you press
r, the app keeps running the old code. Fix the error, save, and pressragain.
Triggering from an IDE
IDEs run flutter run for you, usually under a debugger, and provide buttons for the same actions. The exact icons and shortcuts change between versions, so treat the following as a guide and check your IDE's keymap if something differs.
VS Code
With the Dart and Flutter extensions installed, a floating debug toolbar appears when you start a debug session. It includes a lightning bolt for hot reload and a circular arrow for hot restart. Default shortcuts are:
| Action | Windows and Linux | macOS |
|---|---|---|
| Hot reload | `Ctrl+F5` | `Ctrl+F5` |
| Hot restart | `Ctrl+Shift+F5` | `Cmd+Shift+F5` |
The command palette (Ctrl+Shift+P or Cmd+Shift+P) also lists "Dart: Hot Reload" and "Dart: Hot Restart".
VS Code can reload when you save. This is controlled by the dart.hotReloadOnSave setting in settings.json. Check the setting's documented values for your extension version, because the options include reloading on manual saves only, on all saves, or never.
Android Studio and IntelliJ
When you run an app, the Run panel shows a lightning bolt (hot reload) and a circular arrow (hot restart). Default shortcuts are Ctrl+\ for hot reload and Ctrl+Shift+\ for hot restart on Windows and Linux. On macOS, use Cmd+\ and Cmd+Shift+\.
The Flutter settings page has an option to perform a hot reload on save.
Reload on Save Versus Manual Reload
Reload on save is convenient, but it has a cost. It triggers a reload each time a file is saved, including saves of half-finished code. If you have auto-save turned on in your editor, reloads can fire while you are in the middle of typing. Many developers keep reload on save off for projects where a reload is slow, or use manual-save-only mode.
Triggering with Signals
The flutter tool can listen for Unix signals. This is useful when the tool runs somewhere without a keyboard, or when you want another program (a file watcher or a script) to trigger reloads.
Start the app with a PID file:
flutter run --pid-file /tmp/flutter.pidIn another terminal, send the signals:
# Hot reload
kill -USR1 "$(cat /tmp/flutter.pid)"
# Hot restart
kill -USR2 "$(cat /tmp/flutter.pid)"SIGUSR1 means hot reload and SIGUSR2 means hot restart. This method works on macOS and Linux. Windows does not have these signals in the same way, so use the terminal keys or an IDE there.
Triggering When You Did Not Use flutter run
If the app was started some other way, you can still attach to it:
flutter attachflutter attach connects to a debug app that is already running on a device or emulator, and it accepts the same r and R keys. It only works with debug builds. A profile or release build has no Dart VM with JIT compilation, so there is nothing to reload.
Seeing the Difference Yourself
Reuse the counter from the earlier chapter. Run it, tap the button until the count shows 3, then change the text in build:
import 'package:flutter/material.dart';
void main() => runApp(const MaterialApp(home: CounterPage()));
class CounterPage extends StatefulWidget {
const CounterPage({super.key});
@override
State<CounterPage> createState() => _CounterPageState();
}
class _CounterPageState extends State<CounterPage> {
int _count = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Counter')),
body: Center(child: Text('Taps so far: $_count')),
floatingActionButton: FloatingActionButton(
onPressed: () => setState(() => _count++),
child: const Icon(Icons.add),
),
);
}
}Change 'Count: $_count' to 'Taps so far: $_count', save, and then:
- Press
rin the terminal. The label changes and the number stays at 3. - Press
R. The label stays the same and the number returns to 0.
You can use any trigger from this chapter for each step. The result is the same because each trigger sends the same request.
Choosing a Trigger in Practice
Pick based on your workflow, not on what the app does. The decision between reload and restart depends on the change you made, and a later chapter covers it in depth. For the trigger itself, these rules cover most cases:
- Use the terminal keys if you work in a plain editor, or if you want the output lines to check what happened.
- Use IDE shortcuts if you work in VS Code or Android Studio. They avoid switching windows.
- Use reload on save if your project reloads quickly and you save only complete edits.
- Use signals when a script or remote session triggers reloads.
Edge Cases
- Reload while the app is paused at a breakpoint. The debugger may hold the app paused. Resume first, or the reload may appear to hang.
- Reload during a running restart. Triggering a second action before the first finishes can queue it or be ignored. Wait for the "Reloaded" or "Restarted" line.
- Several devices. If you run on two devices with
flutter run -d all, one key press applies to every attached app. IDEs usually control one debug session at a time. - Web targets. On
flutter run -d chrome, the keys exist, but how hot reload behaves depends on your Flutter version. Hot restart is the dependable choice there. Check the release notes for your version. - Reload rejected. Sometimes the tool prints a message that the reload was rejected and suggests a hot restart. The changed code cannot be applied to the running program. Press
R, or stop and run again if that fails.
Exercise
You press r in the terminal running flutter run after editing a widget. The output says Reloaded 0 of 612 libraries, and the screen does not change. What is the most likely cause, and what do you check first?
Show answer
The tool found no changed source files to send. The most likely cause is that the file was not saved, or the edit is in a file outside the project that the tool is watching. Check that the file is saved, then press r again.
Exercise
You run flutter run --pid-file /tmp/flutter.pid and want a script to hot restart the app. Write the command, and say which signal you would use for a hot reload.
Show answer
Hot restart: kill -USR2 "$(cat /tmp/flutter.pid)". Hot reload uses SIGUSR1: kill -USR1 "$(cat /tmp/flutter.pid)".
Exercise
A teammate says their counter reset to 0 when they pressed r, even though they only changed text in build. They had Caps Lock on. Explain what happened.
Show answer
With Caps Lock on, pressing r sends R, which is hot restart, not hot reload. A hot restart starts the Dart code from main again and resets all state, so the counter returned to 0. Turning off Caps Lock and pressing r keeps the state.