-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commands analyze
albertoodev edited this page Jul 25, 2026
·
7 revisions
The analyze command is the static-analysis engine of the SPM toolchain. It performs deep
AST (Abstract Syntax Tree) inspection of Flutter projects to find every State subclass and
extract rich performance-related metrics from their build methods.
These metrics are the foundation for identifying "heavy" widgets that may benefit from optimization, refactoring, or targeted profiling. Its output is also the manifest consumed by 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| Flag / Option | Short | Description |
|---|---|---|
--output <path> |
-o |
Required. Output JSONL file path. |
--verbose |
-v |
Print per-instance progress to stderr. |
<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 31 State subclasses; kept 31 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. -
State-class discovery.
StateClassVisitoridentifies every FlutterState<T>subclass and locates itsbuildmethod. -
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. Widget-returning helper bodies are resolved transitively, and 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 discoveredStatesubclass, followed internally by a summary event.
One JSON object per line, one line per State subclass. See Output Formats
for the full field reference and an example record, and Extracted Features
for the precise definition of each metric.
- Inventory generation. Automatically find all stateful logic in a large codebase.
- Performance auditing. Surface "hotspots" by filtering for high widget counts or nesting depth.
-
Refactoring guide. Locate components that lean on many helper methods; they are prime
candidates for extraction into dedicated
StatelessWidgets. - Injection preparation. The output is the manifest that inject and run use to decide where to instrument profiling code.
-
Targeted scans. Running
analyzeon specific feature directories keeps result analysis more manageable than scanning an entire project at once. -
JSONL tooling. Process the output with
jqor Python to generate reports and visualizations of your project's UI complexity.
Commands
Reference
Internals
Contributing