maybeOf static method

TabController? maybeOf(
  1. BuildContext context
)

The closest instance of DefaultTabController that encloses the given context, or null if none is found.

Typical usage is as follows:

TabController? controller = DefaultTabController.maybeOf(context);

Calling this method will create a dependency on the closest DefaultTabController in the context, if there is one.

See also:

Implementation

// TODO(framework): Add unit tests to this code snippet.
// https://github.com/flutter/flutter/issues/188530
/// Typical usage is as follows:
///
/// ```dart
/// TabController? controller = DefaultTabController.maybeOf(context);
/// ```
///
/// </callout-box>
///
/// Calling this method will create a dependency on the closest
/// [DefaultTabController] in the [context], if there is one.
///
/// See also:
///
/// * [DefaultTabController.of], which is similar to this method, but asserts
///   if no [DefaultTabController] ancestor is found.
static TabController? maybeOf(BuildContext context) {
  return context.dependOnInheritedWidgetOfExactType<_TabControllerScope>()?.controller;
}