of static method

MediaQueryData of(
  1. BuildContext context

The data from the closest instance of this class that encloses the given context.

You can use this function to query the size and orientation of the screen, as well as other media parameters (see MediaQueryData for more examples). When that information changes, your widget will be scheduled to be rebuilt, keeping your widget up-to-date.

If the widget only requires a subset of properties of the MediaQueryData object, it is preferred to use the specific methods (for example: MediaQuery.sizeOf and MediaQuery.paddingOf), as those methods will not cause a widget to rebuild when unrelated properties are updated.

Typical usage is as follows:

MediaQueryData media = MediaQuery.of(context);

If there is no MediaQuery in scope, this will throw a TypeError exception in release builds, and throw a descriptive FlutterError in debug builds.

See also:

  • maybeOf, which doesn't throw or assert if it doesn't find a MediaQuery ancestor, it returns null instead.


static MediaQueryData of(BuildContext context) {
  return _of(context);