of static method
- 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
.
See also:
- DefaultTabController.maybeOf, which is similar to this method, but returns null if no DefaultTabController ancestor is found.
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!;
}