-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commands analyze
analyze resolves the Dart AST for a Flutter project and finds its rebuild scopes: State
subclasses, ConsumerWidget and HookConsumerWidget classes, and callbacks passed to supported
state-management builders. It writes one JSONL row of build-tree metrics per scope.
The same output serves as the manifest for inject and run.
spm analyze --output results.jsonl /path/to/flutter/project
spm analyze -o results.jsonl /path/to/project1 /path/to/project2
spm analyze -v -o results.jsonl /path/to/project # verbose
spm analyze -o results.jsonl -s State -s BlocBuilder /path/to/project| Flag / Option | Short | Description |
|---|---|---|
--output <path> |
-o |
Required. Output JSONL file path. |
--verbose |
-v |
Print per-instance progress to stderr. |
--scope-types <type> |
-s |
Rebuild scope types to extract; repeatable. Defaults to all of State, ConsumerWidget, Consumer, Selector, BlocBuilder, BlocSelector, BlocConsumer, Obx, GetX, GetBuilder, Observer. -s State reproduces the pre-rebuild-scope output. |
<dir> [dir…] |
One or more Flutter project roots to analyze. |
On completion it prints a summary to stdout:
Scanned 142 files (3 skipped with compile errors); found 47 rebuild scopes (State: 31, BlocBuilder: 12, ConsumerWidget: 4); kept 47 rows.
-
Resolved AST analysis. SPM uses the
analyzerpackage to resolve each Dart compilation unit. Files with error-level diagnostics are skipped and reported in the summary. -
Rebuild-scope discovery.
RebuildScopeAnalysisVisitoridentifies every FlutterState<T>subclass and consumer widget (locating each one'sbuildmethod), plus every builder callback passed inline to a state-management widget. Scopes nest: aBlocBuildercallback inside aState.build()produces its own row, and the enclosingStaterow still counts the widgets the callback builds — a parent rebuild does re-run it. -
Build-tree extraction.
TreeExtractorfollows non-const custom widgets transitively, including the State build of customStatefulWidgetchildren and declarations inpartfiles. -
Metric collection.
BuildMetricsVisitorrecords widgets, helper references, iterations, allocations, list strategy, and layout-dependent builders. Helper bodies are resolved transitively, both those returning aWidgetand those returning a collection of widgets. Local functions are read at their call site, so widgets they build inside a loop are counted per element. The AST complexity extension computes build and helper decision points. -
Normalization and streaming. Metrics are aggregated into an
AnalysisResultModeland emitted as one JSONL row per discovered rebuild scope (filtered by--scope-types), followed internally by a summary event.
One JSON object is written per rebuild scope and tagged with its scopeType. Output
Formats gives the field reference and an example record. Extracted
Features defines each metric.
Pass one or more feature directories when a whole-project result would be too broad. Use
--scope-types State when the output will be used only for SpmState injection; inject can also
accept a full manifest and skip the other scope kinds itself.
Because scopes can nest, summing every row in a file double-counts work shared by a parent scope and
its nested builder callback. Filter or group by scopeType according to the question being asked.
JSONL tools such as jq can process the file without loading it as one large JSON array.
Commands
Reference
Internals
Contributing