Repository: flutter/flutter
File: packages/flutter/lib/src/material/tabs.dart (Dart)

Code before:
  }
}

/// The [ScrollController] for a [TabBar] widget.
final class TabBarScrollController extends ScrollController {
  /// The state of the [TabBar] widget to which this controller is attached.
  ///
  /// Is null if this controller is not attached to a [TabBar].
  _TabBarState? _tabBar;

  set _tabBarState(_TabBarState? tabBarState) {
    _tabBar = tabBarState;
  }

  _TabBarState get _tabBarState {
    assert(debugCheckHasTabBarState());

    return _tabBar!;
  }

  /// Asserts that this controller is currently attached to a [TabBar]'s [State].
  ///
  /// To invoke this function, use the following pattern:
  ///
  /// ```dart
  /// assert(debugCheckHasTabBarState());
  /// ```
  ///
  /// Does nothing if asserts are disabled. Always returns true.
  bool debugCheckHasTabBarState() {
    assert(_tabBar != null, 'This TabBarScrollController is not attached to any TabBar.');

    return true;
  }

  @override
  ScrollPosition createScrollPosition(
    ScrollPhysics physics,
    ScrollContext context,
    ScrollPosition? oldPosition,
  ) {
    return _TabBarScrollPosition(
      physics: physics,
      context: context,
      oldPosition: oldPosition,
      tabBar: _tabBarState,
    );
  }

  @override
  void dispose() {

Review comment (bug):
This is failing analysis, I _think_ there is a pattern that will fix this, see comments with `Examples can assume:` at the top of the file. I think that would do it. We're trying to move away from `{@tool snippet}`, and the other `@tool` directives seem like overkill here.
Another alternative could be to use `assert(debugCheckHasTabBarState());` (just wrapping in backticks).

Code after:
  }
}

/// The [ScrollController] for a [TabBar] widget.
final class TabBarScrollController extends ScrollController {
  /// The state of the [TabBar] widget to which this controller is attached.
  ///
  /// Is null if this controller is not attached to a [TabBar].
  _TabBarState? _tabBarState;

  /// Asserts that this controller is currently attached to a [TabBar]'s [State].
  ///
  /// To invoke this function, wrap it in an assert: `assert(debugCheckHasTabBarState());`
  ///
  /// Does nothing if asserts are disabled. Always returns true.
  bool debugCheckHasTabBarState() {
    assert(_tabBarState != null, 'This TabBarScrollController is not attached to any TabBar.');

    return true;
  }

  @override
  ScrollPosition createScrollPosition(
    ScrollPhysics physics,
    ScrollContext context,
    ScrollPosition? oldPosition,
  ) {
    assert(debugCheckHasTabBarState());

    return _TabBarScrollPosition(
      physics: physics,
      context: context,
      oldPosition: oldPosition,
      tabBar: _tabBarState!,
    );
  }

  @override
  void dispose() {
    _tabBarState = null;
    super.dispose();
  }
}

/// Signature for [TabBar] callbacks that report that an underlying value has
/// changed for a given [Tab] at `index`.
///
/// Used for [TabBar.onHover] and [TabBar.onFocusChange] callbacks The provided
/// `value` being true indicates focus has been gained, or a pointer has hovered
/// over the tab, with false indicated focus has been lost or the pointer has
/// exited hovering.