Files
pipelines/app/lib/shell/detail_pane_navigator.dart
T
alan 41a9e99da8 fix(app): selecting another item closes the previous item's pane page
On a wide split window a run's stage page (or an artifact, a file) opens
inside the detail pane's own navigator. Selecting another run kept that
page on top, so the pane still showed the old stage. ListDetailPanes now
takes the selected item's identity (run, chat or pipeline id) and the
pane navigator pops back to the item when it changes.
2026-10-31 16:30:05 +00:00

59 lines
2.1 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../ui/adaptive/host.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 above the shell's bar, as
/// the item's tabs do. 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. 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 = usesCupertinoHost(context)
? CupertinoPage<void>(key: _rootKey, child: widget.child)
: MaterialPage<void>(key: _rootKey, child: widget.child);
return NavigatorPopHandler(
onPopWithResult: (_) => _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: (_) {},
),
);
}
}