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.
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.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.
- Official migration guide
- MediaQuery.of
- Navigator.of
- Router.of
- Localizations.localeOf
- FocusTraversalOrder.of
- FocusTraversalGroup.of
- Focus.of
- Actions.handler
- Actions.find
- Actions.invoke
- AnimatedList.of
- SliverAnimatedList.of
- MediaQuery.maybeOf
- Navigator.maybeOf
- Router.maybeOf
- Localizations.maybeLocaleOf
- FocusTraversalOrder.maybeOf
- FocusTraversalGroup.maybeOf
- Focus.maybeOf
- Actions.maybeFind
- Actions.maybeInvoke
- AnimatedList.maybeOf
- SliverAnimatedList.maybeOf
- Issue 68637
- Remove nullOk in MediaQuery.of
- Remove nullOk in Navigator.of
- Remove nullOk parameter from AnimatedList.of and SliverAnimatedList.of
- Remove nullOk parameter from Shortcuts.of, Actions.find, and Actions.handler
- Remove nullOk parameter from Focus.of, FocusTraversalOrder.of, and FocusTraversalGroup.of
- Remove nullOk parameter from Localizations.localeOf
- Remove nullOk parameter from Router.of
- Remove nullOk from Scaffold.of and ScaffoldMessenger.of
- Remove nullOk parameter from Cupertino color resolution APIs
- Remove vestigial nullOk parameter from Localizations.localeOf
- Remove nullOk from Actions.invoke, add Actions.maybeInvoke
- 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_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.