9bdabb32d9
Keep the Material-only shell path while preserving public cupertino parameters for callers. Narrow matching tests to Material hosts and behavior because the app always runs under MaterialApp.
67 lines
2.5 KiB
Dart
67 lines
2.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../ui/motion/surface_visibility.dart';
|
|
|
|
/// The open item's own navigator beside a list on a wide window.
|
|
///
|
|
/// A page the item opens (a run's stage page, an artifact, a file) is pushed
|
|
/// here, so it fills the item's pane while the list and the shell's tab bar
|
|
/// stay in place: the page's own tabs then float at the bottom of the pane,
|
|
/// as the item's tabs do (the shell's bar stays under the list). Dialogs still use the root navigator.
|
|
///
|
|
/// The item is this navigator's first page under a fixed key, so a rebuilt
|
|
/// item updates in place and is never remounted. The system Back pops a page
|
|
/// pushed here before it leaves the item (or the shell's previous tab), in
|
|
/// the shown tab only. Opening a different item
|
|
/// ([identity] changes) closes any page the previous item had pushed, so the
|
|
/// pane shows the newly selected item.
|
|
class DetailPaneNavigator extends StatefulWidget {
|
|
const DetailPaneNavigator({super.key, required this.child, this.identity});
|
|
|
|
final Widget child;
|
|
|
|
/// Which item the pane shows (a run, chat or pipeline id).
|
|
final Object? identity;
|
|
|
|
@override
|
|
State<DetailPaneNavigator> createState() => _DetailPaneNavigatorState();
|
|
}
|
|
|
|
class _DetailPaneNavigatorState extends State<DetailPaneNavigator> {
|
|
final GlobalKey<NavigatorState> _navigator = GlobalKey();
|
|
static const _rootKey = ValueKey<String>('list-detail-root');
|
|
|
|
@override
|
|
void didUpdateWidget(covariant DetailPaneNavigator oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
if (oldWidget.identity != widget.identity) {
|
|
_navigator.currentState?.popUntil((route) => route.isFirst);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final Page<void> root = MaterialPage<void>(
|
|
key: _rootKey,
|
|
child: widget.child,
|
|
);
|
|
// Only the shown tab's pane answers the system Back: a page left open in
|
|
// another tab's pane stays there while Back acts on the current tab. The
|
|
// route asks every handler on it, so a hidden pane also ignores the call.
|
|
final shown = SurfaceVisibility.currentOf(context);
|
|
return NavigatorPopHandler(
|
|
enabled: shown,
|
|
onPopWithResult: (_) {
|
|
if (shown) _navigator.currentState?.maybePop();
|
|
},
|
|
child: Navigator(
|
|
key: _navigator,
|
|
pages: [root],
|
|
// The item is never popped from here: its pane closes with the
|
|
// selection, which the owning screen controls.
|
|
onDidRemovePage: (_) {},
|
|
),
|
|
);
|
|
}
|
|
}
|