of static method

TextHeightBehavior of(
  1. BuildContext context
)

The closest instance of DefaultTextHeightBehavior that encloses the given context.

If no such instance exists, this method will assert in debug mode, and throw an exception in release mode.

Typical usage is as follows:

TextHeightBehavior defaultTextHeightBehavior = DefaultTextHeightBehavior.of(context);

Calling this method will create a dependency on the closest DefaultTextHeightBehavior in the context.

See also:

Implementation

static TextHeightBehavior of(BuildContext context) {
  final TextHeightBehavior? behavior = maybeOf(context);
  assert(() {
    if (behavior == null) {
      throw FlutterError(
        'DefaultTextHeightBehavior.of() was called with a context that does not contain a '
        'DefaultTextHeightBehavior widget.\n'
        'No DefaultTextHeightBehavior widget ancestor could be found starting from the '
        'context that was passed to DefaultTextHeightBehavior.of(). This can happen '
        'because you are using a widget that looks for a DefaultTextHeightBehavior '
        'ancestor, but no such ancestor exists.\n'
        'The context used was:\n'
        '  $context',
      );
    }
    return true;
  }());
  return behavior!;
}