ensureLocatorVisible method

Future<bool> ensureLocatorVisible(
  1. CockpitLocator locator, {
  2. Duration duration = const Duration(milliseconds: 220),
  3. CockpitRevealAlignment alignment = CockpitRevealAlignment.nearest,
  4. double padding = 0,
})

Implementation

Future<bool> ensureLocatorVisible(
  CockpitLocator locator, {
  Duration duration = const Duration(milliseconds: 220),
  CockpitRevealAlignment alignment = CockpitRevealAlignment.nearest,
  double padding = 0,
}) async {
  final rootContext = _boundaryKey.currentContext;
  if (rootContext is! Element) {
    return false;
  }

  final resolution = _registry.resolve(locator);
  final resolvedNode = resolution.target?.diagnosticNodeProvider?.call();
  final match = switch (resolvedNode) {
    final Element element when resolution.isSuccess && element.mounted =>
      element,
    _ => _findMountedElementForLocator(rootContext, locator),
  };
  if (match == null) {
    return false;
  }

  final binding = WidgetsBinding.instance;
  final effectiveDuration = _isTestBinding(binding)
      ? Duration.zero
      : duration;
  final revealRequest = _resolveRevealRequest(
    match,
    alignment: alignment,
    padding: padding,
  );
  if (revealRequest == null) {
    return true;
  }
  await Scrollable.ensureVisible(
    match,
    alignment: revealRequest.alignment,
    duration: effectiveDuration,
    curve: Curves.easeOutCubic,
    alignmentPolicy: revealRequest.alignmentPolicy,
  );
  await _applyRevealAdjustment(
    match,
    alignment: alignment,
    padding: padding,
    duration: effectiveDuration,
  );
  return true;
}