Flutter: Binding has not yet been initialized.
Something used a platform channel (Firebase.initializeApp, SharedPreferences, path_provider, a SystemChrome call) before runApp, and runApp is what normally creates the binding those channels depend on. Making main() async and awaiting setup work first is exactly what triggers it. The fix is one line: call WidgetsFlutterBinding.ensureInitialized() before the first await. Widget tests that touch plugins hit the same error without TestWidgetsFlutterBinding.ensureInitialized().
Quick fix
Read the commands before running them. Anything that restarts a service, deletes data or changes permissions should be tried on a non-production system first.
# Find the call that ran too early (the first frame from your own package)
flutter run 2>&1 | grep -A 20 "Binding has not yet been initialized" | grep "package:my_app"
// lib/main.dart: create the binding before any plugin call
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
final prefs = await SharedPreferences.getInstance();
runApp(MyApp(prefs: prefs));
}
// In tests that use plugins
// TestWidgetsFlutterBinding.ensureInitialized();
// Background isolates need their own messenger set up first
// BackgroundIsolateBinaryMessenger.ensureInitialized(rootIsolateToken);
How to diagnose Dart errors
Dart errors are dominated by null safety at runtime and version solving at build time. The null-check operator failure (! on a null) is Dart's equivalent of a NullPointerException and almost always means an assumption about initialisation order was wrong. Pub version solving failures are dependency-graph conflicts and are solved by reading the constraint that pub reports as unsatisfiable, not by deleting the lockfile.
If the quick fix above does not resolve it, work through these steps. They apply to this whole class of error, not just to this one message, which is usually what saves the time.
- Read the full
pub getoutput. It names the two packages whose constraints conflict. Deletingpubspec.lockhides that information without fixing anything. - Replace
!with a null check plus a meaningful error, or withlate finalwhere initialisation genuinely happens before first use. The crash location is where the assumption broke. - Run
flutter doctor -vbefore debugging any build failure. It catches missing Android SDK components and licence acceptance, which produce misleading Gradle errors. - Use
dart pub deps --style=treeto see the resolved graph and find which transitive dependency is pinning an old version. - Clear derived state with
flutter cleanonly after you have read the error. It resets the symptom and loses the evidence.
Tools worth reaching for
flutter doctor -vdart pub depsdart analyzeflutter run --verbose
Authoritative references
Primary documentation for this error, worth reading before applying any fix in production.
Related Dart errors
- Dart: Bad state: Cannot add new events after calling closeA closed StreamController still exists, and something is holding the old reference and adding…
- Dart: Bad state: No elementfirstWhere, first, last or single ran on a collection with nothing in it, or nothing…
- Dart: LateInitializationError: Field 'x' has not been initializedlate promises the compiler that a non nullable field will hold a value before anything reads…
- Dart: Null check operator used on a null valueThe ! null-assertion was applied to an expression that was null at runtime, throwing in…
- Dart: type 'List<dynamic>' is not a subtype of type 'List<String>'jsonDecode always returns plain List and Map objects, whatever the JSON holds, and Dart will…
- Dart: type 'Null' is not a subtype of type 'String' in type castA cast met a null at runtime, and with sound null safety the failure lands on the cast rather…
- Flutter: A RenderFlex overflowed by 42 pixels on the rightA Row or Column laid out children that want more space than the parent offered, so the excess…
- Flutter: Incorrect use of ParentDataWidgetExpanded, Flexible and Positioned only mean something to one kind of parent, and the tree has…
Browse other categories
- HTTP 494xx client errors, 5xx server errors, redirects, headers and protocol problems.
- JavaScript 42npm resolution, async pitfalls, hydration, memory limits and runtime type…
- Database 41Connections, deadlocks, constraints, replication and memory limits.
- AI 35Rate limits, context windows, GPU memory and model-serving failures.
- Network 35Refused connections, timeouts, resets, MTU problems and port exhaustion.
- Python 35Imports, virtual environments, encoding, concurrency and dependency conflicts.
- Kubernetes 34CrashLoopBackOff, ImagePullBackOff, OOMKilled, RBAC, scheduling and storage.
- Docker 27Daemon connectivity, disk space, image pulls, ports and architecture mismatches.
- System 26Disk space, systemd units, file descriptors, OOM killer and scheduled jobs.
- Cloud 25IAM permissions, quotas, service limits and credential failures.
- Security 25JWT validation, CSRF, OAuth grants, SELinux, SSH host keys and CSP.
- TLS 24Untrusted authorities, expiry, hostname mismatch, chains and cipher negotiation.
Something missing or wrong?
This entry is maintained by hand. If the fix is out of date, incomplete, or you have a better one, email a correction and it will be reviewed.