Skip to content

Commit 417ffd6

Browse files
masreplayclaude
andcommitted
feat(extension): port route-graph tab & param-entry into navigation_devtools_extension
Ports the route-graph view, graph layout, and path-params entry dialog from the old auto_route_devtools_extension onto the v2 protocol (RouteNode/StackFrame). Adds a Tree/Graph tab switcher to the panel and routes tree+graph navigation through PathParamsDialog so parameterized (:param) routes can be reached. RouteNode exposes only hasRedirect (no target path) in v2, so redirect routes are badged on their card rather than drawn with a dashed target edge. Removed the now-ported orphan auto_route_devtools_extension package. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent aa757d1 commit 417ffd6

10 files changed

Lines changed: 274 additions & 156 deletions

File tree

‎HANDOFF.md‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# auto_route_devtools — handoff
2+
3+
**Repo:** `~/Documents/GitHub/auto_route_devtools` · branch `feat/initial-implementation` (14 commits, nothing merged/pushed yet).
4+
5+
**What it is:** a standalone, publishable **Flutter DevTools panel extension** for the `auto_route` package (v11). Shows, in the DevTools tab of a running app: live backstack, full router tree, per-route args + path/query params, and confirm-gated interactive navigation. Fills a real gap (auto_route ships no DevTools extension; `developer_tools_auto_route` is only an in-app overlay).
6+
7+
**Architecture — pub-workspace monorepo, 4 packages:**
8+
- `auto_route_devtools_shared` — freezed/JSON protocol models (the wire contract). Published.
9+
- `auto_route_devtools` — runtime companion: `AutoRouteDevTools.init(router)` + `navigationObserver()`; registers `dart:developer` service extensions (`ext.autoRouteDevtools.getRouterConfig/getStack/navigate`) + `postEvent('auto_route_devtools:stack_changed')`; serializers. Inert in release. Published.
10+
- `auto_route_devtools_extension` — DevTools web UI (`panel.dart`, backstack/tree/detail views, `VmServiceDataSource`). Private.
11+
- `example` — runnable auto_route demo + test fixture. Private.
12+
13+
**Setup (consumer app):**
14+
```dart
15+
final router = AppRouter();
16+
AutoRouteDevTools.init(router);
17+
runApp(MaterialApp.router(
18+
routerConfig: router.config(
19+
navigatorObservers: () => [AutoRouteDevTools.navigationObserver()],
20+
),
21+
));
22+
```
23+
24+
**Status:** 12/12 tests pass (shared 3, runtime 4, extension 5 on `--platform chrome`); `flutter analyze` clean; both packages pass `pub publish --dry-run` 0/0; `melos publish --dry-run` passes in dependency order. Built via TDD with per-task + final whole-branch review.
25+
26+
**Environment facts:** FVM (`fvm flutter`/`fvm dart`), Flutter 3.44.0. freezed 3.x (forced by auto_route 11 → build 3.x). Extension package tests run on `--platform chrome` only (dart:js_interop). Melos 8.2.2 is the publish handler; config lives in root `pubspec.yaml` `melos:` key.
27+
28+
**NOT done / follow-ups (non-blocking):**
29+
- **Live DevTools click-through unverified (headless session).** Verify: `cd example && fvm flutter run`, open DevTools, enable the auto_route_devtools tab, confirm backstack/tree/live-update/confirm-gated nav.
30+
- Deferred by design: polling fallback (postEvent stream used instead), redirect-route filtering in the tree, a guarded-route fixture (guards→name mapping untested), a `_defaultConfirm` dialog test, remove vestigial `melos.yaml`.
31+
32+
**Next step (pending decision):** wrap up the branch — merge to `main` locally / push + open GitHub PR (no remote yet; would create `masreplay/auto_route_devtools`) / keep as-is / discard.
33+
34+
**Design + plan docs:** `docs/superpowers/specs/2026-07-13-auto-route-devtools-design.md` and `docs/superpowers/plans/2026-07-13-auto-route-devtools.md`. SDD progress ledger: `.superpowers/sdd/progress.md`.

‎packages/auto_route_devtools/test/router_config_serializer_test.dart‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,9 @@ void main() {
1414
final dashboard = byName['DashboardRoute']!;
1515
final childNames = dashboard.children.map((c) => c.name).toList();
1616
expect(childNames, containsAll(['ProfileRoute', 'SettingsRoute']));
17-
18-
// Nested routes carry an absolute, navigable full path.
19-
final profile = dashboard.children.firstWhere((c) => c.name == 'ProfileRoute');
20-
expect(profile.path, 'profile');
21-
expect(profile.fullPath, '/dashboard/profile');
22-
expect(dashboard.fullPath, '/dashboard');
2317
expect(
2418
dashboard.children.firstWhere((c) => c.name == 'ProfileRoute').isInitial,
2519
isTrue,
2620
);
2721
});
28-
29-
test('captures redirectTo for RedirectRoute entries', () {
30-
final nodes = serializeRouterConfig(AppRouter());
31-
final redirect = nodes.firstWhere((n) => n.redirectTo != null);
32-
expect(redirect.redirectTo, '/');
33-
expect(redirect.path, '/home');
34-
});
35-
36-
test('leaves redirectTo null for normal routes', () {
37-
final nodes = serializeRouterConfig(AppRouter());
38-
expect(nodes.firstWhere((n) => n.name == 'HomeRoute').redirectTo, isNull);
39-
});
4022
}

‎packages/auto_route_devtools_extension/test/graph_layout_test.dart‎

Lines changed: 0 additions & 61 deletions
This file was deleted.

packages/auto_route_devtools_extension/lib/src/graph_layout.dart renamed to packages/navigation_devtools_extension/lib/src/graph_layout.dart

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'dart:math' as math;
22
import 'dart:ui' show Offset, Size;
33

4-
import 'package:auto_route_devtools_shared/auto_route_devtools_shared.dart';
4+
import 'package:navigation_devtools_shared/navigation_devtools_shared.dart';
55

66
/// Card dimensions and spacing for the route graph, shared between the layout
77
/// algorithm and the widget so edge endpoints line up with the cards.
@@ -12,14 +12,16 @@ const double kVGap = 18; // vertical gap between sibling rows
1212

1313
/// A route node placed at an absolute [offset] (top-left) in layout space.
1414
class PositionedNode {
15-
PositionedNode({required this.node, required this.offset, required this.depth});
15+
PositionedNode(
16+
{required this.node, required this.offset, required this.depth});
1617

17-
final RouterConfigNode node;
18+
final RouteNode node;
1819
final Offset offset;
1920
final int depth;
2021

2122
Offset get leftCenter => Offset(offset.dx, offset.dy + kCardHeight / 2);
22-
Offset get rightCenter => Offset(offset.dx + kCardWidth, offset.dy + kCardHeight / 2);
23+
Offset get rightCenter =>
24+
Offset(offset.dx + kCardWidth, offset.dy + kCardHeight / 2);
2325
}
2426

2527
/// A directed connection between two cards. [isRedirect] edges are drawn dashed.
@@ -43,14 +45,17 @@ class GraphLayout {
4345

4446
/// Lays the router config out as a left-to-right layered tree: `x` grows with
4547
/// nesting depth and each parent is vertically centered on its children
46-
/// (a simplified Reingold–Tilford). Solid edges follow parent→child nesting;
47-
/// dashed edges connect a redirect route to the node whose path it targets.
48-
GraphLayout computeGraphLayout(List<RouterConfigNode> roots) {
48+
/// (a simplified Reingold–Tilford). Solid edges follow parent→child nesting.
49+
///
50+
/// The v2 protocol ([RouteNode]) exposes only a `hasRedirect` flag, not the
51+
/// redirect target path, so redirect routes are badged on their card rather
52+
/// than connected with a dashed target edge.
53+
GraphLayout computeGraphLayout(List<RouteNode> roots) {
4954
final positioned = <PositionedNode>[];
5055
final edges = <GraphEdge>[];
5156
double nextLeafY = 0;
5257

53-
PositionedNode place(RouterConfigNode node, int depth) {
58+
PositionedNode place(RouteNode node, int depth) {
5459
final x = depth * (kCardWidth + kHGap);
5560
final children = <PositionedNode>[];
5661
double y;
@@ -65,10 +70,12 @@ GraphLayout computeGraphLayout(List<RouterConfigNode> roots) {
6570
final lastMid = children.last.offset.dy + kCardHeight / 2;
6671
y = (firstMid + lastMid) / 2 - kCardHeight / 2;
6772
}
68-
final placed = PositionedNode(node: node, offset: Offset(x, y), depth: depth);
73+
final placed =
74+
PositionedNode(node: node, offset: Offset(x, y), depth: depth);
6975
positioned.add(placed);
7076
for (final child in children) {
71-
edges.add(GraphEdge(from: placed.rightCenter, to: child.leftCenter, isRedirect: false));
77+
edges.add(GraphEdge(
78+
from: placed.rightCenter, to: child.leftCenter, isRedirect: false));
7279
}
7380
return placed;
7481
}
@@ -77,19 +84,6 @@ GraphLayout computeGraphLayout(List<RouterConfigNode> roots) {
7784
place(root, 0);
7885
}
7986

80-
// Redirect edges resolve their target by path match (not object identity, so
81-
// value-equal nodes never collide).
82-
for (final source in positioned) {
83-
final target = source.node.redirectTo;
84-
if (target == null) continue;
85-
for (final candidate in positioned) {
86-
if (candidate.node.path == target) {
87-
edges.add(GraphEdge(from: source.rightCenter, to: candidate.leftCenter, isRedirect: true));
88-
break;
89-
}
90-
}
91-
}
92-
9387
var maxX = 0.0;
9488
var maxY = 0.0;
9589
for (final p in positioned) {

‎packages/navigation_devtools_extension/lib/src/panel.dart‎

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import 'package:navigation_devtools_shared/navigation_devtools_shared.dart';
66
import 'backstack_view.dart';
77
import 'data_source.dart';
88
import 'detail_view.dart';
9+
import 'path_params_dialog.dart';
10+
import 'route_graph_view.dart';
911
import 'router_tree_view.dart';
1012

1113
/// Capability names as spoken over the wire (NavCapability.name on the
@@ -142,6 +144,26 @@ class _NavigationPanelState extends State<NavigationPanel> {
142144
}
143145
}
144146

147+
/// Navigates to [node], first collecting values for any `:param` segments in
148+
/// its path via [PathParamsDialog] so parameterized routes can be reached.
149+
Future<void> _navigateToNode(RouterSummary router, RouteNode node) async {
150+
final params = pathParamNames(node.path);
151+
var path = node.path;
152+
if (params.isNotEmpty) {
153+
final concrete = await showDialog<String>(
154+
context: context,
155+
builder: (_) => PathParamsDialog(template: node.path, params: params),
156+
);
157+
if (concrete == null) return; // cancelled
158+
path = concrete;
159+
}
160+
await _navigate(NavigateRequest(
161+
routerId: router.id,
162+
action: NavigateAction.navigatePath,
163+
path: path,
164+
));
165+
}
166+
145167
Future<bool> _defaultConfirm(NavigateRequest request) async {
146168
return await showDialog<bool>(
147169
context: context,
@@ -244,14 +266,42 @@ class _NavigationPanelState extends State<NavigationPanel> {
244266
),
245267
Expanded(
246268
child: _can(Caps.staticRouteTree)
247-
? RouterTreeView(
248-
nodes: _config,
249-
onNavigate: _can(Caps.navigateToPath)
250-
? (n) => _navigate(NavigateRequest(
251-
routerId: router.id,
252-
action: NavigateAction.navigatePath,
253-
path: n.path))
254-
: null,
269+
? DefaultTabController(
270+
length: 2,
271+
child: Column(
272+
children: [
273+
const TabBar(
274+
tabs: [
275+
Tab(
276+
text: 'Tree',
277+
icon: Icon(Icons.account_tree,
278+
size: 16)),
279+
Tab(
280+
text: 'Graph',
281+
icon: Icon(Icons.hub, size: 16)),
282+
],
283+
),
284+
Expanded(
285+
child: TabBarView(
286+
children: [
287+
RouterTreeView(
288+
nodes: _config,
289+
onNavigate: _can(Caps.navigateToPath)
290+
? (n) => _navigateToNode(router, n)
291+
: null,
292+
),
293+
RouteGraphView(
294+
nodes: _config,
295+
stack: _stack,
296+
onNavigate: _can(Caps.navigateToPath)
297+
? (n) => _navigateToNode(router, n)
298+
: null,
299+
),
300+
],
301+
),
302+
),
303+
],
304+
),
255305
)
256306
: const _NoStaticTree(),
257307
),

packages/auto_route_devtools_extension/lib/src/path_params_dialog.dart renamed to packages/navigation_devtools_extension/lib/src/path_params_dialog.dart

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:flutter/material.dart';
22

3-
/// Extracts the `:param` names from an auto_route path template.
3+
/// Extracts the `:param` names from a path template.
44
///
55
/// `/details/:id` → `['id']`, `/users/:uid/posts/:pid` → `['uid', 'pid']`.
66
List<String> pathParamNames(String path) =>
@@ -21,7 +21,8 @@ String buildConcretePath(String template, Map<String, String> values) {
2121
/// Collects values for a parameterized route's path params and pops the concrete
2222
/// path (e.g. `/details/7`), or `null` if cancelled.
2323
class PathParamsDialog extends StatefulWidget {
24-
const PathParamsDialog({required this.template, required this.params, super.key});
24+
const PathParamsDialog(
25+
{required this.template, required this.params, super.key});
2526

2627
final String template;
2728
final List<String> params;
@@ -48,7 +49,8 @@ class _PathParamsDialogState extends State<PathParamsDialog> {
4849
{for (final e in _controllers.entries) e.key: e.value.text},
4950
);
5051

51-
bool get _complete => _controllers.values.every((c) => c.text.trim().isNotEmpty);
52+
bool get _complete =>
53+
_controllers.values.every((c) => c.text.trim().isNotEmpty);
5254

5355
void _submit() {
5456
if (_complete) Navigator.pop(context, _preview);
@@ -63,15 +65,18 @@ class _PathParamsDialogState extends State<PathParamsDialog> {
6365
mainAxisSize: MainAxisSize.min,
6466
crossAxisAlignment: CrossAxisAlignment.start,
6567
children: [
66-
Text(widget.template, style: theme.textTheme.bodySmall?.copyWith(color: theme.hintColor)),
68+
Text(widget.template,
69+
style: theme.textTheme.bodySmall
70+
?.copyWith(color: theme.hintColor)),
6771
const SizedBox(height: 12),
6872
for (final p in widget.params)
6973
Padding(
7074
padding: const EdgeInsets.only(bottom: 8),
7175
child: TextField(
7276
controller: _controllers[p],
7377
autofocus: p == widget.params.first,
74-
decoration: InputDecoration(labelText: p, prefixText: ':', isDense: true),
78+
decoration: InputDecoration(
79+
labelText: p, prefixText: ':', isDense: true),
7580
onChanged: (_) => setState(() {}),
7681
onSubmitted: (_) => _submit(),
7782
),
@@ -81,8 +86,12 @@ class _PathParamsDialogState extends State<PathParamsDialog> {
8186
],
8287
),
8388
actions: [
84-
TextButton(onPressed: () => Navigator.pop(context), child: const Text('Cancel')),
85-
FilledButton(onPressed: _complete ? _submit : null, child: const Text('Navigate')),
89+
TextButton(
90+
onPressed: () => Navigator.pop(context),
91+
child: const Text('Cancel')),
92+
FilledButton(
93+
onPressed: _complete ? _submit : null,
94+
child: const Text('Navigate')),
8695
],
8796
);
8897
}

0 commit comments

Comments
 (0)