ensureLocatorVisible method

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

Implementation

Future<bool> ensureLocatorVisible(
  CockpitLocator locator, {
  Duration duration = const Duration(milliseconds: 220),
  CockpitRevealAlignment alignment = CockpitRevealAlignment.nearest,
  double padding = 0,
  double offset = 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 revealTarget = _revealElementForLocator(match);

  // Search steps preserve their requested pacing. Final placement is an
  // atomic jump so nested scrollables cannot leave Cockpit waiting on
  // competing animation futures after the target is already located.
  const effectiveDuration = Duration.zero;
  final revealRequest = _resolveRevealRequest(
    revealTarget,
    alignment: alignment,
    padding: padding,
  );
  if (revealRequest != null) {
    try {
      await Scrollable.ensureVisible(
        revealTarget,
        alignment: revealRequest.alignment,
        duration: effectiveDuration,
        alignmentPolicy: revealRequest.alignmentPolicy,
      );
    } on Object catch (error, stackTrace) {
      FlutterError.reportError(
        FlutterErrorDetails(
          exception: error,
          stack: stackTrace,
          library: 'flutter_cockpit',
          context: ErrorDescription('while revealing a Cockpit target'),
        ),
      );
    }
    await _settleAtomicRevealFrame();
  }
  await _applyRevealAdjustment(
    revealTarget,
    alignment: alignment,
    padding: padding,
    offset: offset,
    duration: effectiveDuration,
  );
  await _settleAtomicRevealFrame();
  return _locatorIsVisible(locator);
}