ensureLocatorVisible method
Future<bool>
ensureLocatorVisible(
- CockpitLocator locator, {
- Duration duration = const Duration(milliseconds: 220),
- CockpitRevealAlignment alignment = CockpitRevealAlignment.nearest,
- double padding = 0,
- 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;
}
// 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(
match,
alignment: alignment,
padding: padding,
);
if (revealRequest != null) {
unawaited(
Scrollable.ensureVisible(
match,
alignment: revealRequest.alignment,
duration: effectiveDuration,
alignmentPolicy: revealRequest.alignmentPolicy,
).catchError((Object error, StackTrace stackTrace) {
FlutterError.reportError(
FlutterErrorDetails(
exception: error,
stack: stackTrace,
library: 'flutter_cockpit',
context: ErrorDescription('while revealing a Cockpit target'),
),
);
}),
);
await _settleAtomicRevealFrame();
}
await _applyRevealAdjustment(
match,
alignment: alignment,
padding: padding,
offset: offset,
duration: effectiveDuration,
);
await _settleAtomicRevealFrame();
return _locatorIsVisible(locator);
}