Learn
Audit routes and inspect logical stacks
Check route declarations, parameter round trips and deep-link plans, then inspect retained stacks without changing navigation.
Need to check that the Catalog module works in both guest and signed-in placements, or see which pages remain in a retained tab? Start with the step-by-step example. It includes the entire runnable test on one page; this guide explains the API and its limits.
Version 2.3.0 adds the optional inspection.dart library. Use
ark_navigation: ^2.4.1 in an application. Run the complete example below
from the package source repository, where its test dependencies are declared.
Use these tools when composing feature modules or diagnosing a stack. They do not replace navigation, execute policies or create another event history.
Run the complete example first
flutter test example/inspection_example_test.dart
The complete example creates a Shell with Catalog and Profile scopes. One Catalog module is mounted twice: guest navigation in the root scope and signed-in navigation in the Catalog scope.
The test audits the graph, checks both placements, decodes an old product link into its canonical URI and parent plan, then captures the retained tab stacks. It uses Widgets types without Material or Cupertino. It is a functional test example, not a visual application.
Add the optional import
import 'package:ark_navigation/ark_navigation.dart';
import 'package:ark_navigation/inspection.dart';
The main library keeps the navigation API. The second import provides audit reports, expectations, inspection DTOs and the formatter.
Check declarations before building
Once your application has populated its NavigationGraphBuilder:
final NavigationAuditReport report = builder.audit();
if (!report.isValid) {
print(const NavigationInspectionFormatter().formatAudit(report));
return;
}
final NavigationGraph graph = builder.build();
The report can show several independent errors and both declaration positions for a conflict. Its codes, severity, locations and coverage are typed. It contains neither exception values nor a concrete failed URI.
Audit does not freeze the builder or authorize a later build. Changing a
declaration can invalidate the result; build() always validates the actual
configuration with the same internal rules. A duplicate enabled URI pattern
remains an error. Mounting one module twice at distinct paths is valid.
The audit can only inspect objects already constructed. A Route constructor that rejects a missing required codec still throws before that Route can enter the builder. A missing or duplicate dependency can make downstream checks incomplete; independent valid branches are still checked.
Check a Destination with its actual parameters
NavigationRouteAuditor.checkDestination<D, R> takes a graph, a typed
Destination, optional requested Mount/Scope and a required
NavigationRouteExpectation. The expectation specifies the exact Route,
Mount, Scope and canonical URI. A required nullable canonicalUri means that
null explicitly expects no URI, rather than skipping the check.
It checks the resolved placement, the exact declared result type R, the URI,
and restoration of the supplied Destination. Supply sameDestination to
compare business parameters, for example productId. The executable example
shows the full call and both mount expectations.
This extra comparison matters. An encoder that always emits a fixed product
URI can remain perfectly canonical while losing the original productId.
Comparing only a type, an ID assigned to a Route, toString(), or even URI
stability does not prove parameter preservation.
Without a comparator, a URI-bearing case is incomplete and isValid is false. If there is no URI, semantic restoration is not applicable. A session-only route that nevertheless supplies a codec can still be checked as a URI-bearing case. The auditor does not change restoration policy.
Check aliases and the entire deep-link plan
checkUri<D, R> takes the input URI, expected Destination, expected canonical
placement and an ordered expectedPlan of NavigationRouteExpectation values.
It calls the existing graph decoder and resolves every target in the returned
plan. It compares each element's Route/Mount/Scope/URI and the complete length.
For example, an old /account/catalog/item/demo-product link should become
/account/catalog/products/demo-product and restore Catalog followed by
Product in the signed-in Mount. Reversed parents, a missing target and an
unexpected placement are failures, not silently corrected plans.
These checks do not evaluate Redirect, Guard, platform-domain allowlists, page builders or Controller operations. They validate examples, not every possible value or authentication state. Codec, stack-plan and comparison callbacks execute explicitly: keep them pure and deterministic. A synchronous callback cannot be forcibly cancelled by a timeout.
Read coverage before treating a result as success
| Property | Meaning |
|---|---|
| isValid | All applicable checks completed without errors |
| isComplete | No required stage was skipped and findings were not truncated |
| hasErrors | Errors occurred, including findings beyond the retention limit |
| checks | Passed, failed, incomplete or notApplicable for each attempted stage |
| isTruncated | Findings exceeded maxIssues, which defaults to 200 |
A mismatch can be fully checked and still fail. An unavailable comparison is incomplete. Neither case is success. maxIssues limits retained findings, not callback time or the cost of comparing every pattern.
Inspect the graph and one Session
final NavigationGraphInspection graphView =
const NavigationInspector().captureGraph(graph);
final NavigationSessionInspection frame = controller.inspect();
const NavigationInspectionFormatter formatter = NavigationInspectionFormatter();
print(formatter.formatGraph(graphView));
print(formatter.formatSession(frame));
Graph metadata includes declared modules, scopes, mounts, patterns and restoration policy. Disabled mounts remain visible. The session frame contains its identity, Graph/Snapshot revisions, scope relationships, active-child links and ordered Entry metadata. Destination type means the declared route type, not the concrete object's runtimeType.
Capture retains no Controller, Graph, Snapshot, Destination, callback, context, actual URI, error or stack trace. An Entry records only whether it has a URI. A custom Route Base need not implement NavigationRouteTypeMetadata; missing type metadata is reported as unavailable and capture is incomplete, not an invalid route declaration.
Graph scopes intentionally contain no runtime Entries or active-child selection; those belong to the Session frame. Section completeness is explicit through scopesComplete/modulesComplete/mountsComplete and each module/scope's isComplete.
Frames are immutable historical values. They do not update when navigation changes and require no disposal or subscription. The owner still closes the Controller/Session; a new controller.inspect() after disposal throws.
For several windows, explicitly choose
runtime.session(id).controller.inspect(). There is no global inspector or
automatic cross-session history.
Logical active does not mean visible or allowed to pop
The recorded active-child chain does not include actual Navigator visibility, covered host pages or pageless dialogs. The formatter labels it logical. It does not infer Native Back permission, run Guards, or substitute Snapshot.currentUri for the host-aware Controller.currentUri.
The text view is useful in a debug console or an application-owned development screen. It is not a bundled DevTools GUI.
Limits and privacy
NavigationInspectionLimits defaults to 1,000 configuration records and 500 Entries per frame. Scope, Module, Route, pattern and Mount records share the configuration budget. A partial scope cannot establish its true top Entry; the formatter does not label its retained prefix as top.
Formatter output defaults to 20,000 UTF-16 units including a truncation marker; maxCharacters must be at least 32. Control characters in identifiers are escaped. Limits count records/text, not a strict byte ceiling for arbitrary user-provided labels.
Identifiers, static prefixes and declared patterns may themselves contain sensitive information. Nothing is automatically sent to a log service, file or network. Do not publish a capture merely because it omits Destination data.
For ongoing request events, keep using NavigationTraceRecorder. Inspector frames and traces answer different questions and do not own each other's lifetime.