of static method

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 device parameters (see PlatformQueryData for more examples). When that information changes, your widget will be scheduled to be rebuilt, keeping your widget up-to-date.

Typical usage is as follows:

PlatformQueryData device = PlatformQuery.of(context);

If there is no PlatformQuery 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 PlatformQuery ancestor, it returns null instead.

Implementation

static PlatformQueryData of(BuildContext context) {
  return context.dependOnInheritedWidgetOfExactType<PlatformQuery>()!.data;
}