Short answer
Find the variable named in the error and the stack trace line that reads it. Then give it a value before that line runs: in initState, not in an async method that finishes later, or where it is declared. If it can really be missing for a while, drop late, make it nullable (Type?) and check for null where it is read. If you added the field while the app was running, do a hot restart first: hot reload keeps the screens already open, so their initState does not run again.
Why the variable has no value yet, and the fix
01
Set in an async method, read in build
“If you fail to initialize a late variable, a runtime error occurs when the variable is used.” Dart, Variables: late variables
initState calls an async _init() that awaits something, then sets the late field. build runs right after initState, before the await finishes, and reads the field. Make the field nullable and show a loader until it is set, or keep the Future and use a FutureBuilder.
VideoPlayerController? _controller; Future<void> _init() async { final c = VideoPlayerController.networkUrl(Uri.parse(widget.videoUrl)); await c.initialize(); if (!mounted) return; setState(() => _controller = c); } @override Widget build(BuildContext context) { final c = _controller; if (c == null) return const CircularProgressIndicator(); return VideoPlayer(c); } @override void dispose() { _controller?.dispose(); super.dispose(); }02
A field set on only some paths
“When you mark a variable as late but initialize it at its declaration, then the initializer runs the first time the variable is used.” Dart, Variables: late variables
The field is set in an if branch, a callback, a listener or didChangeDependencies, and read on a path where that code never ran. Give it a value on every path before it is read, or initialize it where it is declared. A late field with an initializer runs that code the first time it is read, so it is never unset.
// runs the first time _repo is read late final _repo = UserRepository(widget.api);03
late added to silence a null-safety error
“every time the field is read, a runtime check is inserted to make sure it has been assigned a value. If it hasn't, an exception is thrown.” Dart, Understanding null safety
Adding late makes the compiler error “Non-nullable instance field must be initialized” go away, but it moves the check to runtime. If the value can be missing at any point, the honest type is nullable: Type? with a check where it is read.
Checked against the vendor’s docs on : Dart: Variables (late variables); Dart: Understanding null safety (late variables); Flutter: Hot reload.
Rather hand it over?
Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.
- from $450App Fix TicketOne reproducible bug in an existing mobile or web app, diagnosed and fixed.See scope and start
- from $450AI-Built App RescueA Lovable, Bolt or Cursor app checked end to end in 3 days, then its worst problems fixed at a fixed price.No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.See scope and start
Related: Flutter “Null check operator used on a null value” · Flutter “type 'Null' is not a subtype of type 'String'” · Flutter “Looking up a deactivated widget’s ancestor is unsafe” · Dart “Bad state: No element”