of static method

The resolver (GranularLayout) from the closest GranularLayoutWidget instance that encloses the given context.

Implementation

static GranularLayout of(BuildContext context) {
  final resolverAncestor = context.dependOnInheritedWidgetOfExactType<LayoutResolverInheritedWidget>();

  if (resolverAncestor == null) {
    throw StateError('No ancestor with `LayoutResolverInheritedWidget` (of type GranularLayout)');
  }

  final resolver = resolverAncestor.resolver;
  if (resolver is! GranularLayout) {
    throw StateError(
      'Found `LayoutResolverInheritedWidget` ancestor of type ${resolver.runtimeType}. Expected a `GranularLayout`.',
    );
  }

  return resolver;
}