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. class DetailPaneNavigator extends StatefulWidget { const DetailPaneNavigator({super.key, required this.child}); final Widget child; @override State createState() => _DetailPaneNavigatorState(); } class _DetailPaneNavigatorState extends State { final GlobalKey _navigator = GlobalKey(); static const _rootKey = ValueKey('list-detail-root'); @override Widget build(BuildContext context) { final Page root = usesCupertinoHost(context) ? CupertinoPage(key: _rootKey, child: widget.child) : MaterialPage(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: (_) {}, ), ); } }