Skip to content
Boring Doc
BreakingHigh impactOfficial migration guidesince 2.0.0landed 1.24.0

Eliminating nullOk Parameters

Framework · Official source

This migration guide describes conversion of code that uses the `nullOk` parameter on multiple `of` static accessors and related accessors to use alternate APIs with nullable return values.

Original behavior

Flutter has a common pattern of allowing lookup of some types of widgets (`InheritedWidget`s) using static member functions that are typically called `of`, and take a `BuildContext`.

New behavior

The actual change modified these APIs to not have a `nullOk` parameter, and to return a non-nullable value:

Who is affected
Applications and packages relying on the previous behaviour or signature. Code that uses InheritedWidget, BuildContext, MediaQuery.of and related APIs.
Practical impact
Behaviour or API differences that can break builds or change runtime behaviour.
What action should I take?
Follow the official migration guide below, update affected call sites, run `dart fix --apply` where a fix is available, then run your tests.
Official migration guide (excerpt, © The Flutter Authors, CC BY 3.0)

In order to modify your code to use the new form of the APIs, convert all instances of calls that include nullOk = true as a parameter to use the maybe form of the API instead.

So this:

MediaQueryData? data = MediaQuery.of(context, nullOk: true);

becomes:

MediaQueryData? data = MediaQuery.maybeOf(context);

You also need to modify all instances of calling the API with nullOk = false (often the default), to accept non-nullable return values, or remove any ! operators:

So either of:

MediaQueryData data = MediaQuery.of(context)!; // nullOk false by default.
MediaQueryData? data = MediaQuery.of(context); // nullOk false by default.

both become:

MediaQueryData data = MediaQuery.of(context); // No ! or ? operator here now.

The unnecessary_non_null_assertion analysis option can be quite helpful in finding the places where the ! operator should be removed, and the unnecessary_nullable_for_final_variable_declarations analysis option can be helpful in finding unnecessary question mark operators on final and const variables.

Migration assistantAI-generated · grounded in cited sources
AI explanations are not configured
Set AI_PROVIDER (for example to openai-compatible with a local Ollama or LM Studio endpoint) to enable grounded explanations. Everything else on this page works without an AI provider.
Official migration guide·Verified classification (95%)

Listed in the official breaking-changes index (docs.flutter.dev/release/breaking-changes).

An official announcement or migration guide documents an intended behaviour or API change. A verified source change (git diff) shows code changed but does not by itself prove a public API is breaking. AI interpretations are labelled and never used to classify a change.

Source commit
b3045439b7c0
Source last updated
Oct 21, 2026
Last synchronized
Oct 21, 2026
Publication status
published
Publication history
  • Oct 21, 2026, 8:31 PM: new → published (ingestion) — Backed by an official breaking-change/migration guide.
AI explanationAI-generated · grounded in cited sources
AI explanations are not configured
Set AI_PROVIDER (for example to openai-compatible with a local Ollama or LM Studio endpoint) to enable grounded explanations. Everything else on this page works without an AI provider.
Was this useful?