Sub topic 12
Troubleshooting a Reload That Seems to Do Nothing
This chapter assumes you can run an app with flutter run, tell a StatelessWidget from a StatefulWidget, and recognize initState and build. It also assumes you have read the earlier chapters on what hot reload preserves and which changes it cannot apply.
Sometimes you edit code, save, press r, and the screen looks the same. Most of the time the reload worked and the code you changed did not run again. This chapter gives you an order for checking, so you can find the cause without restarting at random.
Step 1: Read what the terminal said
Before you suspect your code, read the output of flutter run. A successful hot reload prints a line like this:
Reloaded 1 of 1017 libraries in 543ms (compile: 21 ms, reload: 233 ms, reassemble: 187 ms).The first number tells you how many Dart libraries changed. Three outcomes are common:
Reloaded 1 of N: Flutter saw your edit and applied it. If the screen did not change, the changed code did not run again (see steps 3 and 4).Reloaded 0 of N: Flutter saw no changed file. Your edit was not saved, you edited a file the app does not import, or the terminal is attached to a different run.- A compile error or a "reload rejected" message: the new code was not applied. The old code keeps running, so the screen looks unchanged.
If nothing printed at all, the reload command never reached the tool. Check that the terminal running flutter run has focus when you press r.
Step 2: Follow the decision path
The diagram shows the order in which to check things. Each branch is explained in the sections below.
Cause 1: The edited code runs only once
Hot reload swaps in new code and then rebuilds the widget tree. It does not re-run code that executes a single time. Three places are the usual suspects:
initStateof aStateobject that already exists.main().- Initializers of global variables and static fields.
This example caches a greeting in initState:
import 'package:flutter/material.dart';
void main() => runApp(const MaterialApp(home: GreetingPage()));
class GreetingPage extends StatefulWidget {
const GreetingPage({super.key});
@override
State<GreetingPage> createState() => _GreetingPageState();
}
class _GreetingPageState extends State<GreetingPage> {
late String _greeting;
@override
void initState() {
super.initState();
_greeting = 'Hello';
}
@override
Widget build(BuildContext context) {
return Scaffold(body: Center(child: Text(_greeting)));
}
}Change 'Hello' to 'Hi there', save, and hot reload. The screen still says Hello. The reload applied your edit, but the existing State object already ran initState. A hot restart creates a new State object, so initState runs again and the screen shows Hi there.
Global and static initializers behave the same way:
int globalCounter = 10;
class Config {
static int retries = 3;
}Flutter treats these as state. Changing 10 to 20 and hot reloading leaves the running value untouched until a restart.
If you only want to see the new text while you tweak it, move the value into build or a getter:
String get _greeting => 'Hi there';A getter runs every time it is read, so hot reload picks up the change. Use this as a development shortcut. Do not restructure real code just to avoid restarts.
Cause 2: A cached value in a State field
The initState case has a broader form. Any value computed once and stored keeps its old result, even if the code that produced it changed. Common examples are:
- A
Futurestored in a field so thatFutureBuilderdoes not refetch. - A controller created with initial values, such as
TextEditingController(text: 'abc'). - A list built once from constants.
- A singleton or service that reads configuration on creation.
class _ProfileState extends State<Profile> {
late final Future<String> _name = _loadName();
Future<String> _loadName() async => 'Ada';
@override
Widget build(BuildContext context) {
return FutureBuilder<String>(
future: _name,
builder: (context, snapshot) => Text(snapshot.data ?? 'Loading'),
);
}
}If you change _loadName to return 'Grace' and hot reload, the stored Future has already completed with 'Ada'. The new method body is in memory but nothing calls it. A hot restart fixes this. The same applies to a Provider, Bloc, or any object held above the widget you edited: the old instance survives.
Cause 3: The edit never reached the running app
When the terminal says Reloaded 0 of N libraries, the problem is outside your code.
- The file is not saved. Terminal
rreads files from disk, so an unsaved buffer is invisible. IDEs can reload on save, but the setting may be off. - The file is not imported. A file that no running code imports is not part of the app. Check that your widget is actually used.
- You are editing a copy. Two checkouts of a project, or a package copied into
.pub-cache, can make you edit a file the app does not use. For a path dependency, confirmpubspec.yamlpoints to the folder you are editing. - The run is on a different device or is stale. If you started
flutter runtwice, the terminal you pressrin may not be the one attached to the emulator you are looking at. - The build is not debug. Hot reload needs debug mode, which uses the Dart VM's JIT compiler. A profile or release build, started with
--profileor--release, has no reload support.
flutter run -d <device-id>Pass the device explicitly when more than one is connected. flutter devices lists the IDs.
Cause 4: A rejected reload or a compile error
If your edit has a syntax error, the compiler refuses it and the previous version of the app keeps running. The error is printed in the terminal and in the IDE's output panel. It is easy to miss when the app window is in front.
Some valid edits are also rejected because hot reload cannot apply them. Typical cases are:
- Changing an
enuminto a regular class, or the reverse. - Changing the type parameters of a generic class.
- Changing a class so that it has a different kind of declaration, for example turning a class into a mixin.
- Removing a class that live objects still use.
Flutter usually prints a message that suggests a hot restart. Follow it. If the message is vague, press R.
Cause 5: Changes outside Dart code
Not every edit is Dart code that the VM can swap in.
| Change | What to do |
|---|---|
| Android Kotlin, Java, or Gradle files | Stop and run again |
| iOS Swift, Objective-C, or Podfile changes | Stop and run again |
| A new plugin or an edit to `pubspec.yaml` dependencies | Run `flutter pub get`, then stop and run again |
| Added or edited assets, such as images and fonts | Hot restart often suffices. Add new asset paths to `pubspec.yaml` and do a full restart if the asset is still missing |
| Permissions in `AndroidManifest.xml` or `Info.plist` | Stop and run again |
Native code is compiled into the app binary when you launch it. The Dart VM cannot patch it live, so only a new build includes the change.
Cause 6: Platform and tooling differences
Hot reload is not equally available everywhere.
- On the web, the default
rhas historically performed a hot restart. Hot reload for the web is newer and may require an experimental flag depending on your Flutter version. Check the output offlutter run -d chromefor the actions it offers. - IDE buttons and terminal keys call the same machinery, but some IDEs reload on save and others do not. If saving does nothing, use the lightning-bolt reload button or the terminal key.
- If the debug connection drops, for example after you unplug a device, keys stop working. Rerun
flutter run.
Step 3: Climb the fallback ladder
When the cause is unclear, escalate one rung at a time, and stop at the first that works:
- Hot reload (
r). Confirm theReloaded N of Mline. - Hot restart (
R). This resets all Dart state and re-runsmain. - Stop with
q, then runflutter runagain. This rebuilds native code and reloads plugins. - Clear build artifacts, then rebuild.
flutter clean
flutter pub get
flutter runRunning flutter clean is a last resort, because it forces a slow rebuild. If you needed it, a stale build cache is the likely cause.
Using reassemble to confirm that a reload happened
If you cannot tell whether a reload reached your widget, log from State.reassemble. Flutter calls it on every existing State during a hot reload, and it is not called by a hot restart, which creates new objects:
class _GreetingPageState extends State<GreetingPage> {
int _count = 0;
@override
void reassemble() {
super.reassemble();
debugPrint('reassemble: reloaded, _count is still $_count');
}
@override
Widget build(BuildContext context) {
return Text('Count: $_count');
}
}If the message prints but the screen is unchanged, the reload ran and your edit is in code that does not re-execute (causes 1 and 2). If the message never prints, the reload did not reach the widget (causes 3 and 4).
Symptom checklist
| Symptom | Likely cause | Fix |
|---|---|---|
| `Reloaded 0 of N libraries` | File unsaved, unused, or wrong run | Save, check imports, check the device |
| Error text in the terminal | Compile error or rejected change | Fix the code, reload, or press `R` |
| Initial value looks old | Set in `initState` or a field initializer | Hot restart |
| Global or static value looks old | Initializer not re-run | Hot restart |
| `main` edit ignored | `main` not re-run | Hot restart |
| New plugin or native code missing | Needs a new build | Stop, run again |
| Nothing works after repeated tries | Stale build cache | `flutter clean`, then run |
Exercise
You change a text field's starting text from TextEditingController(text: 'abc') to TextEditingController(text: 'xyz'), where the controller is created in initState. After hot reload the terminal prints Reloaded 1 of 800 libraries but the field still shows abc. Why, and what should you do?
Show answer
The reload applied your edit, but the existing State object already ran initState and kept the old controller with abc. Hot reload does not re-run initState. Press R for a hot restart, which creates a new State and runs initState with the new value.
Exercise
After saving an edit and pressing r, the terminal prints Reloaded 0 of 800 libraries. Name three things to check.
Show answer
Any three of these: the file was saved to disk, the edited file is imported by code the app uses, you edited the right copy of the project or package, and the terminal you pressed r in is attached to the device you are watching. Also check that the app is running in debug mode.
Exercise
You add a reassemble override that logs a message. You hot restart with R. Will the message print, and why?
Show answer
No. Hot restart destroys the old State objects and creates new ones, so reassemble is not called. It is called on existing State objects during a hot reload.