of static method

MaterialInkController of(
  1. BuildContext context
)

The ink controller from the closest instance of Material that encloses the given context within the closest LookupBoundary.

If no Material widget ancestor can be found then this method will assert in debug mode, and throw an exception in release mode.

Typical usage is as follows:

MaterialInkController inkController = Material.of(context);

This method can be expensive (it walks the element tree).

See also:

Implementation

static MaterialInkController of(BuildContext context) {
  final MaterialInkController? controller = maybeOf(context);
  assert(() {
    if (controller == null) {
      if (LookupBoundary.debugIsHidingAncestorRenderObjectOfType<_RenderInkFeatures>(context)) {
        throw FlutterError(
          'Material.of() was called with a context that does not have access to a Material widget.\n'
          'The context provided to Material.of() does have a Material widget ancestor, but it is '
          'hidden by a LookupBoundary. This can happen because you are using a widget that looks '
          'for a Material ancestor, but no such ancestor exists within the closest LookupBoundary.\n'
          'The context used was:\n'
          '  $context',
        );
      }
      throw FlutterError(
        'Material.of() was called with a context that does not contain a Material widget.\n'
        'No Material widget ancestor could be found starting from the context that was passed to '
        'Material.of(). This can happen because you are using a widget that looks for a Material '
        'ancestor, but no such ancestor exists.\n'
        'The context used was:\n'
        '  $context',
      );
    }
    return true;
  }());
  return controller!;
}