Sub topic 10
When Only a Full Restart Works
This chapter assumes you can run an app with flutter run, that you know what hot reload and hot restart each do, and that you know the difference between Dart code and the native Android or iOS project that hosts it.
Hot reload and hot restart both work inside one running process. Some changes can't be applied that way, so you have to stop the app and start it again. This chapter covers which changes those are, why they need it, and how to do it quickly.
What a full restart is
A full restart means ending the running app and launching it again. With the command line, press q in the flutter run terminal, or press Ctrl+C. Then run flutter run again. In an IDE, use the Stop button and then Run or Debug.
It differs from hot restart in what gets thrown away:
| Action | Dart VM process | Native host app | Native build step |
|---|---|---|---|
| Hot reload | Kept | Kept | Skipped |
| Hot restart | Kept, with a fresh isolate state | Kept | Skipped |
| Full restart | Replaced | Replaced | Runs again |
The build step in the last column matters most. Hot reload and hot restart send new Dart code to a VM that is already running. They don't run Gradle, Xcode, or CocoaPods, and they don't reinstall the app. Anything the native build produces is frozen until you rebuild.
Changes that need a full restart
Native code and native configuration
Flutter's Dart code runs inside a host app. On Android that host is a Kotlin or Java project under android/. On iOS it is a Swift or Objective-C project under ios/. Edits to these files change the host, and the host is compiled and installed by the native toolchain. Examples:
- Kotlin, Java, Swift, or Objective-C source, including the code behind a platform channel.
AndroidManifest.xml,build.gradlefiles, andInfo.plist.- Permissions, entitlements, and URL scheme registrations.
- App icons, launch screens, and splash configuration.
- Native dependencies such as CocoaPods and Gradle libraries.
Hot reload can't see any of this. Your Dart edits show up and the native edits silently do nothing, which is a common source of confusion.
New or changed packages
Editing pubspec.yaml to add a dependency changes what the app is built from. Pure Dart packages are sometimes picked up without a rebuild, but you shouldn't rely on it. Packages that include native code (plugins) are different. Their native parts have to be compiled and registered with the host app, so adding one always requires a full restart. A reload that appears to work can then fail at runtime with a MissingPluginException.
The safe habit is to stop the app after you edit pubspec.yaml, run flutter pub get, and start again.
Values fixed at launch
Some values are decided when the app is started, not when your Dart code runs. The main case is compile-time environment values passed with --dart-define. Neither hot reload nor hot restart reads the flags again.
import 'package:flutter/material.dart';
const apiBase = String.fromEnvironment(
'API_BASE',
defaultValue: 'https://api.example.com',
);
void main() => runApp(const MaterialApp(home: EnvPage()));
class EnvPage extends StatelessWidget {
const EnvPage({super.key});
@override
Widget build(BuildContext context) {
return const Scaffold(
body: Center(child: Text('API: $apiBase')),
);
}
}Start it with a value:
flutter run --dart-define=API_BASE=https://staging.example.comIf you change the flag to a different URL, you must stop and run the command again with the new flag. Pressing R in the existing session keeps the old launch arguments. The same applies to build flavors (--flavor) and to the choice of target file (-t).
Structural changes to types
Hot reload rebuilds classes in the VM, and a few structural edits can't be mapped onto the existing running objects. The Flutter documentation lists these as cases hot reload can reject:
- Changing an enum into a regular class, or the other way around.
- Changing the type parameters of a generic class.
- Changing a class in ways that make live instances incompatible with the new definition.
When this happens, the tool prints a message saying the reload was rejected and suggests a hot restart. A hot restart fixes most of these. If it doesn't, treat the app as needing a full restart. Compile errors also block both actions until you fix them.
Why hot restart is not enough
Hot restart resets your Dart program. It throws away the widget tree, all State objects, and the values of globals and statics, then runs main again. But it does not touch the native side. This has two consequences.
First, native code is not rebuilt, as described above.
Second, native state survives. Suppose a Kotlin plugin keeps a singleton, such as an open database connection, a Bluetooth session, or a registered listener. A hot restart creates a new Dart isolate that talks to the same old native objects. This can cause surprising behavior:
- A listener registered before the restart may now deliver events twice, once for each Dart session that registered it.
- A native object still holds state from your previous run, so your app doesn't start from a clean slate.
- A plugin that expects to be initialized once may throw on the second initialization.
If you are debugging an issue that involves a plugin and a clean start, a full restart is the only way to guarantee the native side is also fresh.
import 'package:flutter/services.dart';
const _channel = MethodChannel('example.com/battery');
Future<int> readBatteryLevel() async {
final level = await _channel.invokeMethod<int>('getBatteryLevel');
return level ?? -1;
}Here readBatteryLevel is Dart code, and you can edit it with hot reload. The handler for getBatteryLevel is native code in MainActivity.kt or AppDelegate.swift. A change to that handler needs a full restart. If you rename the channel string on the Dart side only, a hot reload will apply it, and every call will then fail until the native side uses the same name and you rebuild.
Deciding quickly
Ask where the changed file lives and when its value is decided.
The order of escalation is a good default. Start with hot reload because it is fastest. Move to hot restart if the Dart state needs resetting. Move to a full restart when the change lives outside Dart, or when a hot restart doesn't produce a clean result.
Making full restarts less painful
A full restart on a native build can take a long time, so a few habits help:
- Batch native edits. Make all the Kotlin, Swift, and manifest changes you need, then restart once.
- Keep native code thin. Put logic in Dart where hot reload works, and keep the native handler as small as possible.
- Don't rerun
flutter createorflutter cleanunless something is truly stale. A normal full restart reuses build caches.flutter cleandeletes them and makes the next build much slower. - If a native change seems ignored after a full restart, check that you edited the right project. Files under
build/are generated output and get overwritten.
Quick reference
| Change | Needed action |
|---|---|
| Widget `build` code, styling, text | Hot reload |
| Value set in `initState` | Hot restart |
| Edits to `main` or global and static initializers | Hot restart |
| Kotlin, Java, Swift, or Objective-C source | Full restart |
| `AndroidManifest.xml`, `Info.plist`, Gradle files | Full restart |
| Adding a plugin in `pubspec.yaml` | Full restart |
| Changing `--dart-define`, `--flavor`, or `-t` | Full restart with the new flags |
| Reload rejected for an enum or generic type change | Hot restart, then full restart if needed |
Exercise
You add the url_launcher plugin to pubspec.yaml, run flutter pub get, press r, and the app throws a MissingPluginException when you tap a link. Why did hot reload not fix it, and what should you do?
Show answer
url_launcher contains native Android and iOS code that must be compiled and registered with the host app. Hot reload only patches Dart code in the running VM and never runs the native build, so the plugin's native side was never installed. Pressing R for a hot restart has the same limit. Stop the app and run flutter run again, which rebuilds and reinstalls it with the plugin registered.
Exercise
The EnvPage example above prints the value of API_BASE. You launched with --dart-define=API_BASE=https://staging.example.com, then want to see the production URL. You edit the default value in the code and press R, but the page still shows the staging URL. Explain why and give two ways to see the new value.
Show answer
The --dart-define value is fixed when the app is launched, and a hot restart reuses the original launch arguments, so the staging value still wins over the default in code. You can stop the app and run it again with --dart-define=API_BASE=https://api.example.com, or stop it and run flutter run with no flag so the defaultValue in the code is used.