of static method

TabController of(
  1. BuildContext context
)

The closest instance of DefaultTabController that encloses the given context.

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

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

Typical usage is as follows:
link
TabController controller = DefaultTabController.of(context);

See also:

Implementation

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