Skip to content

Commit 6c8bb18

Browse files
committed
feat: dialog & bottom-sheet visibility — pageless tracking verified, paired-observer recipe tested and documented
Navigator1Adapter already captures showDialog/showModalBottomSheet as pageless frames (regression-tested, poppable from the panel). go_router and auto_route route state never contains pageless routes, so the documented recipe is pairing their adapter with a Navigator1Adapter observer on the same navigator — proven by tests in both packages. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GpNWM852Ee3GJFEeJEd4vN
1 parent cae6aca commit 6c8bb18

7 files changed

Lines changed: 232 additions & 1 deletion

File tree

‎README.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,26 @@ import 'package:navigation_devtools_test/navigation_devtools_test.dart';
7474
runAdapterConformanceTests('MyAdapter', AdapterHarness(...));
7575
```
7676

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+
7797
## Prior art
7898

7999
- Flutter DevTools ships no navigation/backstack inspector.

‎packages/auto_route_devtools/README.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ NavigationDevTools.register(adapter);
3333
- Your `AutoRouteDevTools.init(...)` / `navigationObserver()` wiring keeps working unchanged.
3434
- The DevTools tab is now called **navigation_devtools** (the panel moved into the shared core package and also supports Navigator 1.0, custom `RouterDelegate`s, and go_router).
3535

36+
## Dialogs & bottom sheets
37+
38+
`showDialog`/`showModalBottomSheet` are pageless routes on the raw Navigator — auto_route's stack never includes them. To see them in the panel, pair the adapter with a `Navigator1Adapter` observer:
39+
40+
```dart
41+
final pageless = Navigator1Adapter(label: 'Pageless routes');
42+
NavigationDevTools.register(pageless);
43+
// in your router config:
44+
navigatorObservers: () => [AutoRouteDevTools.navigationObserver(), pageless.observer],
45+
```
46+
3647
## Prior art
3748

3849
- auto_route ships no DevTools extension (as of v11); [`developer_tools_auto_route`](https://pub.dev/packages/developer_tools_auto_route) is an in-app overlay, not a DevTools panel.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import 'package:auto_route_devtools/auto_route_devtools.dart';
2+
import 'package:auto_route_example/router.dart';
3+
import 'package:flutter/material.dart';
4+
import 'package:flutter_test/flutter_test.dart';
5+
import 'package:navigation_devtools/navigation_devtools.dart';
6+
import 'package:navigation_devtools_shared/navigation_devtools_shared.dart';
7+
8+
/// Dialogs/bottom sheets are pageless routes on the raw Navigator —
9+
/// auto_route's stackData never contains them. The supported recipe is to
10+
/// pair the AutoRouteAdapter with a Navigator1Adapter observer on the same
11+
/// router's navigator.
12+
void main() {
13+
testWidgets(
14+
'showDialog is invisible to AutoRouteAdapter but visible via a paired '
15+
'Navigator1Adapter observer', (tester) async {
16+
final router = AppRouter();
17+
final autoAdapter = AutoRouteAdapter(router);
18+
final pageless = Navigator1Adapter(label: 'auto_route pageless routes');
19+
20+
await tester.pumpWidget(MaterialApp.router(
21+
routerConfig: router.config(
22+
navigatorObservers: () => [autoAdapter.observer, pageless.observer],
23+
),
24+
));
25+
await tester.pumpAndSettle();
26+
27+
final context = router.navigatorKey.currentContext!;
28+
showDialog<void>(
29+
context: context,
30+
builder: (_) => const AlertDialog(title: Text('Hi')),
31+
);
32+
await tester.pumpAndSettle();
33+
34+
expect(
35+
autoAdapter.currentStack().map((f) => f.name),
36+
isNot(contains(contains('DialogRoute'))),
37+
);
38+
final top = pageless.currentStack().last;
39+
expect(top.kind, StackFrameKind.pageless);
40+
expect(top.name, contains('DialogRoute'));
41+
42+
final result = await pageless.navigate(NavigateRequest(
43+
routerId: pageless.id, action: NavigateAction.pop));
44+
await tester.pumpAndSettle();
45+
expect(result.ok, isTrue);
46+
expect(find.text('Hi'), findsNothing);
47+
});
48+
}

‎packages/go_router_devtools/README.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ Run your app and open the **navigation_devtools** tab in Flutter DevTools. (The
2323
- **Route tree** from `configuration.routes`; routes with a `redirect` callback get a `redirect` badge (redirects are closures, so only their presence can be shown).
2424
- **Interactive navigation**: navigate by path (`go`), push by route name, and pop — each behind a confirm dialog.
2525

26+
## Dialogs & bottom sheets
27+
28+
`showDialog`/`showModalBottomSheet` are pageless routes on the raw Navigator — GoRouter's route matches never include them. To see them in the panel, pair this adapter with a `Navigator1Adapter` observer on the same router:
29+
30+
```dart
31+
final pageless = Navigator1Adapter(label: 'Pageless routes');
32+
final router = GoRouter(observers: [pageless.observer], routes: [...]);
33+
NavigationDevTools.register(GoRouterAdapter(router));
34+
NavigationDevTools.register(pageless);
35+
```
36+
37+
The panel then shows both views in its router selector.
38+
2639
## Version compatibility
2740

2841
Depends on `go_router ^16.0.0` (pinned against 16.3.0 internals: `RouteMatchList`, `ShellRouteMatch`). The adapter's contract is enforced by the `navigation_devtools` conformance kit in this package's tests.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:go_router/go_router.dart';
4+
import 'package:go_router_devtools/go_router_devtools.dart';
5+
import 'package:navigation_devtools/navigation_devtools.dart';
6+
import 'package:navigation_devtools_shared/navigation_devtools_shared.dart';
7+
8+
/// Dialogs/bottom sheets are pageless routes on the raw Navigator — GoRouter's
9+
/// RouteMatchList never sees them. The supported recipe is to pair the
10+
/// GoRouterAdapter with a Navigator1Adapter observer on the same router.
11+
void main() {
12+
testWidgets(
13+
'showDialog is invisible to GoRouterAdapter but visible via a paired '
14+
'Navigator1Adapter observer', (tester) async {
15+
final pageless = Navigator1Adapter(label: 'GoRouter pageless routes');
16+
final router = GoRouter(
17+
observers: [pageless.observer],
18+
routes: [
19+
GoRoute(
20+
path: '/',
21+
builder: (_, _) => Builder(
22+
builder: (context) => Scaffold(
23+
body: ElevatedButton(
24+
onPressed: () => showDialog<void>(
25+
context: context,
26+
builder: (_) => const AlertDialog(title: Text('Hi')),
27+
),
28+
child: const Text('dialog'),
29+
),
30+
),
31+
),
32+
),
33+
],
34+
);
35+
final goAdapter = GoRouterAdapter(router);
36+
37+
await tester.pumpWidget(MaterialApp.router(routerConfig: router));
38+
await tester.pumpAndSettle();
39+
40+
await tester.tap(find.text('dialog'));
41+
await tester.pumpAndSettle();
42+
43+
// The router-level view knows nothing about the dialog...
44+
expect(
45+
goAdapter.currentStack().map((f) => f.name),
46+
isNot(contains(contains('DialogRoute'))),
47+
);
48+
// ...but the paired raw-navigator view shows it as a pageless frame.
49+
final top = pageless.currentStack().last;
50+
expect(top.kind, StackFrameKind.pageless);
51+
expect(top.name, contains('DialogRoute'));
52+
53+
// And the panel can close it through the pageless adapter.
54+
final result = await pageless.navigate(NavigateRequest(
55+
routerId: pageless.id, action: NavigateAction.pop));
56+
await tester.pumpAndSettle();
57+
expect(result.ok, isTrue);
58+
expect(find.text('Hi'), findsNothing);
59+
});
60+
}

‎packages/navigation_devtools/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void main() {
3535

3636
- Passing your `routes:` map unlocks the route-table pane and path/name navigation; without it the adapter can still show the live stack and pop.
3737
- `onGenerateRoute` factories are opaque code and cannot be enumerated.
38-
- Anonymous `Navigator.push(MaterialPageRoute(...))` entries appear with a `pageless` badge and a synthesized name.
38+
- Anonymous `Navigator.push(MaterialPageRoute(...))` entries — **including dialogs and bottom sheets** (`showDialog`, `showModalBottomSheet`) — appear with a `pageless` badge and a synthesized name (`DialogRoute<void>`, `ModalBottomSheetRoute<void>`), and can be popped from the panel.
3939
- Nested `Navigator`s: register one adapter per navigator (a `NavigatorObserver` can only observe one); the panel shows them in its router selector.
4040

4141
## Custom RouterDelegate apps (Navigator 2.0)
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:navigation_devtools/navigation_devtools.dart';
4+
import 'package:navigation_devtools_shared/navigation_devtools_shared.dart';
5+
6+
void main() {
7+
Future<Navigator1Adapter> pumpApp(WidgetTester tester) async {
8+
final adapter = Navigator1Adapter();
9+
await tester.pumpWidget(MaterialApp(
10+
navigatorObservers: [adapter.observer],
11+
home: Builder(
12+
builder: (context) => Scaffold(
13+
body: Column(children: [
14+
ElevatedButton(
15+
onPressed: () => showDialog<void>(
16+
context: context,
17+
builder: (_) => const AlertDialog(title: Text('Hi')),
18+
),
19+
child: const Text('dialog'),
20+
),
21+
ElevatedButton(
22+
onPressed: () => showModalBottomSheet<void>(
23+
context: context,
24+
builder: (_) => const SizedBox(height: 100),
25+
),
26+
child: const Text('sheet'),
27+
),
28+
]),
29+
),
30+
),
31+
));
32+
await tester.pumpAndSettle();
33+
return adapter;
34+
}
35+
36+
testWidgets('showDialog appears on the stack as a pageless DialogRoute',
37+
(tester) async {
38+
final adapter = await pumpApp(tester);
39+
var fired = 0;
40+
adapter.changes.listen((_) => fired++);
41+
42+
await tester.tap(find.text('dialog'));
43+
await tester.pumpAndSettle();
44+
45+
final top = adapter.currentStack().last;
46+
expect(top.kind, StackFrameKind.pageless);
47+
expect(top.name, contains('DialogRoute'));
48+
expect(top.isActive, isTrue);
49+
expect(fired, greaterThan(0));
50+
51+
// Panel-driven pop closes the dialog.
52+
final result = await adapter.navigate(NavigateRequest(
53+
routerId: adapter.id, action: NavigateAction.pop));
54+
await tester.pumpAndSettle();
55+
expect(result.ok, isTrue);
56+
expect(adapter.currentStack().last.name, isNot(contains('DialogRoute')));
57+
expect(find.text('Hi'), findsNothing);
58+
});
59+
60+
testWidgets('showModalBottomSheet appears as a pageless route and pops off',
61+
(tester) async {
62+
final adapter = await pumpApp(tester);
63+
64+
await tester.tap(find.text('sheet'));
65+
await tester.pumpAndSettle();
66+
67+
final top = adapter.currentStack().last;
68+
expect(top.kind, StackFrameKind.pageless);
69+
expect(top.name, contains('ModalBottomSheetRoute'));
70+
71+
// Closing the sheet in-app removes it from the shadow stack.
72+
Navigator.of(tester.element(find.text('sheet'))).pop();
73+
await tester.pumpAndSettle();
74+
expect(
75+
adapter.currentStack().map((f) => f.name),
76+
isNot(contains(contains('ModalBottomSheetRoute'))),
77+
);
78+
});
79+
}

0 commit comments

Comments
 (0)