of static method
- BuildContext context
Returns the FlutterView that the provided context will render into.
Throws if the context is not associated with a FlutterView.
The method creates a dependency on the context, which will be informed
when the identity of the FlutterView changes (i.e. the context is
moved to render into a different FlutterView then before). The context
will not be informed when the properties on the FlutterView itself
change their values. To access the property values of a FlutterView
prefer using the access methods on MediaQuery, such as
MediaQuery.sizeOf, which will ensure that the context is informed when
the view properties change.
See also:
- View.maybeOf, which throws instead of returning null if no FlutterView is found.
Implementation
static FlutterView of(BuildContext context) {
  final FlutterView? result = maybeOf(context);
  assert(() {
    if (result == null) {
      final bool hiddenByBoundary =
          LookupBoundary.debugIsHidingAncestorWidgetOfExactType<_ViewScope>(context);
      final List<DiagnosticsNode> information = <DiagnosticsNode>[
        if (hiddenByBoundary) ...<DiagnosticsNode>[
          ErrorSummary(
            'View.of() was called with a context that does not have access to a View widget.',
          ),
          ErrorDescription(
            'The context provided to View.of() does have a View widget ancestor, but it is hidden by a LookupBoundary.',
          ),
        ] else ...<DiagnosticsNode>[
          ErrorSummary(
            'View.of() was called with a context that does not contain a View widget.',
          ),
          ErrorDescription(
            'No View widget ancestor could be found starting from the context that was passed to View.of().',
          ),
        ],
        ErrorDescription(
          'The context used was:\n'
          '  $context',
        ),
        ErrorHint('This usually means that the provided context is not associated with a View.'),
      ];
      throw FlutterError.fromParts(information);
    }
    return true;
  }());
  return result!;
}