cartographer 0.2.1
cartographer: ^0.2.1 copied to clipboard
Auto-discover and visualize a Flutter app's navigation graph as an interactive sitemap. Dev-only.
cartographer #
Auto-discover and visualize a Flutter app's navigation graph as an interactive sitemap.
Dev-only β never bundled into your release build.
π¦ pub.dev: pub.dev/packages/cartographer
Install #
Cartographer is a CLI tool you point at a project, not a library you import. Install it once with dart pub global from pub.dev:
dart pub global activate cartographer
Then from any Flutter project:
cartographer --project . --watch
Note: cartographer depends on
analyzer ^13.0.0, which requiresmeta ^1.18.0. The current stable Flutter SDK pinsmetaat an older version, so you cannot currently add cartographer as adev_dependenciesentry in a Flutter project'spubspec.yamlβ pub resolution will fail. Global activation sidesteps the conflict because cartographer resolves its own dependencies independently of your app.
Use #
cartographer # extract current dir, serve, open browser
cartographer --watch # live-reload on lib/ changes
cartographer --project ../some-app # analyze a different project
cartographer --output map.json # CI mode: write JSON, no server
cartographer --fixture map.json # serve a pre-extracted snapshot (fast viewer iteration)
cartographer --port 8765 # pin a port (default: random free port)
cartographer --no-open # don't auto-open browser
You can also drop any cartographer JSON snapshot directly onto the viewer (or pick one with the "Upload JSONβ¦" button) β useful for sharing a snapshot with someone who doesn't have your project source.
What it detects #
runApp(MyApp())β sets the entry node.MaterialApp(home: X)(alsoCupertinoApp,WidgetsApp) β connects the root widget to its first screen so the entry chain doesn't break.- Direct
Navigator.push*calls βpush,pushReplacement,pushAndRemoveUntil(and named variants) overMaterialPageRoute,CupertinoPageRoute, orPageRouteBuilder. Navigator.of(context).push(...).- Custom navigation helpers β any top-level function or method that takes a
Widgetparameter and internally callsNavigator.push*is automatically recognized. Calls to it are recorded as push edges with the widget arg as the destination. Catches common app patterns likenavigateWithFade(context, screen)orpushScreen(context, screen). - State-class attribution β pushes performed inside
_MyScreenStateare credited toMyScreen.
Viewer features #
- 2D and 3D modes in a single page; toggle in the top-right. Mode persists across reloads.
- Light and dark themes that respect
prefers-color-schemeby default, with a manual toggle. - Path mode β toggle on, click any node to see the shortest BFS path from the entry chain. The whole reachable graph is colored by depth (green β lime β yellow β amber β orange β red β crimson). Each node's step number renders inside its circle.
- Filters β click categories to hide/show.
- Focus on click β clicking a node frames it + its direct neighbours.
- 3D extras β floor grid, orientation gizmo (FRONT/TOP/RIGHT cube), zoom / pan / grid tool stack, auto-rotate toggle.
Configuration #
Drop a cartographer.yaml at the project root to customize categories and the layout:
categories:
- id: auth
label: Authentication
match: lib/views/auth/ # any file under here gets cat: auth
- id: home
label: Home Shell
match: lib/views/home/
anchors:
auth: { fx: 0.18, fy: 0.25 } # fractional canvas coords for the cluster
home: { fx: 0.50, fy: 0.30 }
exclude:
- lib/generated/ # skip these files entirely
All keys are optional. Without a config, cartographer infers categories from file paths and arranges clusters in a circle.
What it doesn't (yet) #
- Named routes /
MaterialApp.routestables. go_routerandauto_route.- Embedded children (one widget inside another's
build()). - Runtime-built route tables.
Example app #
example/ contains a fictional bookstore β 24 screens organized into auth / home / browse / cart / profile / settings flows, with navigation depth 5 and a mix of direct Navigator.push and a custom pushScreen helper. To visualize it from a checkout of this repo:
flutter pub get -C example
cartographer --project example --watch
You should see 26 nodes and 32 edges across 7 categories.
License #
MIT β see LICENSE.