|
1 | | -# auto_route_devtools (monorepo) |
| 1 | +# navigation_devtools (monorepo) |
2 | 2 |
|
3 | | -A Flutter DevTools panel extension for [auto_route](https://pub.dev/packages/auto_route) that surfaces the live backstack, the full router tree, route args/params, and confirm-gated interactive navigation directly inside Flutter DevTools. Unlike auto_route (which ships no DevTools extension) and `developer_tools_auto_route` (an in-app overlay), this is a proper DevTools panel. |
| 3 | +One Flutter DevTools panel for **every** kind of Flutter navigation. Inspect the live backstack, browse the declared route tree, view per-route args/params, and drive confirm-gated navigation from the panel — whether your app uses Navigator 1.0, a hand-written Navigator 2.0 `RouterDelegate`, go_router, or auto_route. |
4 | 4 |
|
5 | | -- Package: [`packages/auto_route_devtools/`](packages/auto_route_devtools/) — the publishable package and its README/setup guide. |
6 | | -- Design docs: [`docs/superpowers/`](docs/superpowers/) — specs and implementation plans. |
| 5 | + |
| 6 | + |
| 7 | +## Packages |
| 8 | + |
| 9 | +| Package | What it is | Use it when | |
| 10 | +|---|---|---| |
| 11 | +| [`navigation_devtools`](packages/navigation_devtools/) | Core: adapter API, DevTools panel bundle, Navigator 1.0 + generic RouterDelegate adapters, adapter conformance test kit | `MaterialApp(routes:)`, imperative push/pop, or a custom `RouterDelegate` | |
| 12 | +| [`go_router_devtools`](packages/go_router_devtools/) | go_router adapter | `MaterialApp.router(routerConfig: GoRouter(...))` | |
| 13 | +| [`auto_route_devtools`](packages/auto_route_devtools/) | auto_route v11 adapter | `MaterialApp.router(routerConfig: appRouter.config())` | |
| 14 | + |
| 15 | +The DevTools panel ships once, inside `navigation_devtools`; the adapter packages depend on it, so depending on any one of them gets you the panel. Every affordance in the panel is **capability-aware** — a router that can't enumerate its routes simply shows no tree pane; one that can't deep-link shows no path field. |
| 16 | + |
| 17 | +## Quick start |
| 18 | + |
| 19 | +Pick the adapter matching your navigation setup (each snippet is mirrored by a runnable app under [`examples/`](examples/)): |
| 20 | + |
| 21 | +**Navigator 1.0** ([example](examples/navigator1_example/)): |
| 22 | + |
| 23 | +```dart |
| 24 | +final adapter = Navigator1Adapter(routes: appRoutes); |
| 25 | +NavigationDevTools.register(adapter); |
| 26 | +runApp(MaterialApp(routes: appRoutes, navigatorObservers: [adapter.observer])); |
| 27 | +``` |
| 28 | + |
| 29 | +**Custom RouterDelegate** ([example](examples/router_delegate_example/)): |
| 30 | + |
| 31 | +```dart |
| 32 | +NavigationDevTools.register(RouterDelegateAdapter(delegate, parser: parser)); |
| 33 | +runApp(MaterialApp.router(routerDelegate: delegate, routeInformationParser: parser)); |
| 34 | +``` |
| 35 | + |
| 36 | +**go_router** ([example](examples/go_router_example/)): |
| 37 | + |
| 38 | +```dart |
| 39 | +NavigationDevTools.register(GoRouterAdapter(router)); |
| 40 | +runApp(MaterialApp.router(routerConfig: router)); |
| 41 | +``` |
| 42 | + |
| 43 | +**auto_route** ([example](examples/auto_route_example/)): |
| 44 | + |
| 45 | +```dart |
| 46 | +AutoRouteDevTools.init(router); |
| 47 | +runApp(MaterialApp.router( |
| 48 | + routerConfig: router.config( |
| 49 | + navigatorObservers: () => [AutoRouteDevTools.navigationObserver()], |
| 50 | + ), |
| 51 | +)); |
| 52 | +``` |
| 53 | + |
| 54 | +Then run your app and open the **navigation_devtools** tab in Flutter DevTools. |
| 55 | + |
| 56 | +## Capability matrix |
| 57 | + |
| 58 | +| Capability | Navigator 1.0 | RouterDelegate | go_router | auto_route | |
| 59 | +|---|---|---|---|---| |
| 60 | +| Static route tree | ✅ with `routes:` map | ❌ | ✅ incl. shells | ✅ | |
| 61 | +| Guard / redirect badges | ❌ | ❌ | ✅ redirect flag | ✅ guard names | |
| 62 | +| Navigate by path | ✅ | ✅ with parser | ✅ `go()` | ✅ | |
| 63 | +| Push by name | ✅ | ❌ | ✅ | ❌ | |
| 64 | +| Pop | ✅ | ✅ | ✅ | ✅ | |
| 65 | +| Nested routers | one adapter per `Navigator` | ❌ | ✅ shells | ✅ | |
| 66 | + |
| 67 | +## Writing your own adapter |
| 68 | + |
| 69 | +Implement `NavigationAdapter` (see [`packages/navigation_devtools`](packages/navigation_devtools/)) and validate it with the bundled conformance kit: |
| 70 | + |
| 71 | +```dart |
| 72 | +import 'package:navigation_devtools_test/navigation_devtools_test.dart'; |
| 73 | +
|
| 74 | +runAdapterConformanceTests('MyAdapter', AdapterHarness(...)); |
| 75 | +``` |
| 76 | + |
| 77 | +## Dialogs & bottom sheets |
| 78 | + |
| 79 | +`showDialog`, `showModalBottomSheet`, and friends push **pageless routes** on the raw `Navigator` — router packages (go_router, auto_route) never see them in their own state. |
| 80 | + |
| 81 | +- **Navigator 1.0 apps:** nothing to do — dialogs and sheets appear on the backstack automatically, badged `pageless` (e.g. `DialogRoute<void>`), and can be popped from the panel. |
| 82 | +- **go_router / auto_route / custom delegates:** pair your adapter with a `Navigator1Adapter` observer on the same navigator; it shows up as a second router in the panel's selector, carrying the raw stack including dialogs: |
| 83 | + |
| 84 | +```dart |
| 85 | +// go_router |
| 86 | +final pageless = Navigator1Adapter(label: 'Pageless routes'); |
| 87 | +final router = GoRouter(observers: [pageless.observer], routes: [...]); |
| 88 | +NavigationDevTools.register(GoRouterAdapter(router)); |
| 89 | +NavigationDevTools.register(pageless); |
| 90 | +
|
| 91 | +// auto_route |
| 92 | +navigatorObservers: () => [adapter.observer, pageless.observer] |
| 93 | +``` |
| 94 | + |
| 95 | +Both recipes are regression-tested (`dialogs_with_nav1_observer_test.dart` in each adapter package). |
| 96 | + |
| 97 | +## Prior art |
| 98 | + |
| 99 | +- Flutter DevTools ships no navigation/backstack inspector. |
| 100 | +- auto_route and go_router ship no DevTools extension (go_router only offers `debugLogDiagnostics` console logging; `developer_tools_auto_route` is an in-app overlay, not a DevTools panel). |
| 101 | + |
| 102 | +## Repository layout |
| 103 | + |
| 104 | +Design docs and implementation plans live in [`docs/superpowers/`](docs/superpowers/). The DevTools panel source is [`packages/navigation_devtools_extension/`](packages/navigation_devtools_extension/) (unpublished; prebuilt into the core package — rebuild with `dart run devtools_extensions build_and_copy --source=. --dest=../navigation_devtools/extension/devtools`). |
0 commit comments