7ff012880b
Provide composable shown/current visibility for retained surfaces and migrate visibility readers away from TickerMode. This keeps ticker muting separate from painted and current-surface state.
68 lines
2.6 KiB
Dart
68 lines
2.6 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../ui/adaptive/host.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 = usesCupertinoHost(context)
|
|
? CupertinoPage<void>(key: _rootKey, child: widget.child)
|
|
: 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: (_) {},
|
|
),
|
|
);
|
|
}
|
|
}
|