observe method
Implementation
@override
Future<UiObservation> observe([
ObservationOptions options = const ObservationOptions(),
]) async {
return await RunnerBenchmark.async('observer', 'observe', () async {
RunnerBenchmark.dimension(
'synchronizationPolicy', options.synchronization.name);
RunnerBenchmark.dimension('observationDetail', options.detail.name);
RunnerBenchmark.dimension('keyedOnly', options.keyedOnly);
var partial = false;
switch (options.synchronization) {
case ObservationSynchronization.immediate:
break;
case ObservationSynchronization.nextFrame:
await tester.pump();
break;
case ObservationSynchronization.untilStable:
final timeout = options.stableTimeout ?? settleTimeout;
try {
await _settleUntilStable(timeout);
} on FlutterError {
partial = true;
}
break;
}
// Minimal observations are deliberately locator-oriented. They avoid
// enabling semantics and describe only keyed controls, which keeps
// branch/control-flow checks from paying for the report tree. Standard
// observations retain the report tree contract. Diagnostic observations
// add cheap, ambiguity-checked locator hints after the same full walk.
final minimal = options.detail == ObservationDetailLevel.minimal;
// Identity/freshness always includes bounds so presentation options
// (includeBounds) cannot change stale-target validation.
final built = _buildElements(
includeBounds: true,
keyedOnly: options.keyedOnly || minimal,
enableSemantics: !minimal,
useSemantics: !minimal,
);
final screen = _screenObservation();
final fingerprint = fingerprintForObservation(
screen: screen,
elements: built.elements,
);
final revision = _applyFingerprint(fingerprint);
final observationId = nextObservationId();
registry.registerObservation(
observationId: observationId,
handles: rebindHandles(observationId, built.handles),
);
final detailedElements =
options.detail == ObservationDetailLevel.diagnostic
? annotateDiagnosticLocators(built.elements)
: built.elements;
final elements = options.includeBounds && !minimal
? detailedElements
: detailedElements.map(_withoutBounds).toList(growable: false);
final size = tester.view.physicalSize / tester.view.devicePixelRatio;
return UiObservation(
observationId: observationId,
revision: revision,
timestamp: DateTime.now().toUtc(),
screen: screen,
elements: elements,
viewport: UiViewport(
width: size.width,
height: size.height,
devicePixelRatio: tester.view.devicePixelRatio,
),
observableFingerprint: fingerprint,
completeness: ObservationCompleteness(
semanticTree: !minimal,
runtimeMetadata: true,
navigationState: !screen.unknown,
screenshot: false,
partial: partial,
),
);
});
}