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

Code before:
/// @docImport 'icon_button.dart';
/// @docImport 'popup_menu.dart';
library;

import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';

import 'colors.dart';
import 'text_theme.dart';
import 'theme.dart';
import 'tooltip_theme.dart';
import 'tooltip_visibility.dart';

/// Signature for when a tooltip is triggered.
typedef TooltipTriggeredCallback = void Function();

/// Signature for computing the position of a tooltip.
///
/// The arguments are:
/// * `target`: The offset of the target the tooltip is positioned near in the global coordinate system.
/// * `size`: The size of the overlay in which the tooltip is being positioned.
/// * `childSize`: The size of the tooltip itself.
/// * `verticalOffset`: The configured vertical offset.
/// * `preferBelow`: Whether the tooltip prefers to be positioned below the target.
///
/// Returns the offset from the top left of the overlay to the top left of the tooltip.
typedef TooltipPositionDelegate = Offset Function({
  required Offset target,
  required Size size,
  required Size childSize,
  required double verticalOffset,
  required bool preferBelow,
});

/// A special [MouseRegion] that when nested, only the first [_ExclusiveMouseRegion]
/// to be hit in hit-testing order will be added to the BoxHitTestResult (i.e.,
/// child over parent, last sibling over first sibling).
///
/// The [onEnter] method will be called when a mouse pointer enters this
/// [MouseRegion], and there is no other [_ExclusiveMouseRegion]s obstructing
/// this [_ExclusiveMouseRegion] from receiving the events. This includes the
/// case where the mouse cursor stays within the paint bounds of an outer
/// [_ExclusiveMouseRegion], but moves outside of the bounds of the inner
/// [_ExclusiveMouseRegion] that was initially blocking the outer widget.
///
/// Likewise, [onExit] is called when the a mouse pointer moves out of the paint

Review comment (suggestion):
Not sure if this would be helpful for users to calculate the offset. It's fine to me. Can we add one more parameter like "targetSize" to this callback? I think it would be helpful to calculate the tooltip position. For example, if we want the tooltip to show up on the upper right corner of the target, this parameter would be useful. WDYT:)? I think the target size info can be found in `OverlayChildLayoutInfo`.

Code after:
/// @docImport 'icon_button.dart';
/// @docImport 'popup_menu.dart';
library;

import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';

import 'colors.dart';
import 'text_theme.dart';
import 'theme.dart';
import 'tooltip_theme.dart';
import 'tooltip_visibility.dart';

/// Signature for when a tooltip is triggered.
typedef TooltipTriggeredCallback = void Function();

/// Contextual information for positioning a tooltip.
///
/// This immutable data class contains all the necessary information for computing
/// the position of a tooltip relative to its target widget.
///
/// See also:
///
///  * [TooltipPositionDelegate], which uses this context to compute tooltip positions.
@immutable
class TooltipPositionContext {
  /// Creates a tooltip position context.
  const TooltipPositionContext({
    required this.target,
    required this.targetSize,
    required this.tooltipSize,
    required this.verticalOffset,
    required this.preferBelow,
  });

  /// The center point of the target widget in the global coordinate system.
  final Offset target;

  /// The size of the target widget that triggers the tooltip.
  final Size targetSize;

  /// The size of the tooltip itself.
  final Size tooltipSize;

  /// The configured vertical offset.
  final double verticalOffset;