Files
pipelines/app/lib/shell/list_detail.dart
T
alan c0d68f7c47 Split view: drag the divider to resize the list pane, remembered per destination
A 12 px grab area over the divider line resizes the list live (mouse,
touch, arrow keys; double tap resets to the default policy). The shell bar
over the list follows. Widths persist per destination in SharedPreferences
and clamp to the window without overwriting the saved value. Capture kit
gains hover= and drag= steps.
2026-11-03 10:49:09 +00:00

230 lines
8.2 KiB
Dart

import 'dart:math' as math;
import 'package:flutter/material.dart';
import '../ui/adaptive/floating_bar_layout.dart';
import 'detail_pane_navigator.dart';
import 'list_detail_policy.dart';
import 'list_pane_divider.dart';
import 'list_pane_widths.dart';
import 'shell_bar.dart';
export 'list_detail_policy.dart';
/// The system's own insets (status bar, navigation bar) as the shell saw
/// them, before its scaffold replaced them with its bars' heights.
///
/// A Material [Scaffold] with an app bar and a bottom bar removes the top and
/// bottom padding *and* view padding from its body, so a pane beside the list
/// cannot recover the status-bar inset from its own [MediaQuery]. The shell
/// publishes the insets here; outside a shell the view padding stands in.
class ShellSystemInsets extends InheritedWidget {
const ShellSystemInsets({
super.key,
required this.padding,
required super.child,
});
final EdgeInsets padding;
static EdgeInsets of(BuildContext context) =>
context
.dependOnInheritedWidgetOfExactType<ShellSystemInsets>()
?.padding ??
MediaQuery.viewPaddingOf(context);
@override
bool updateShouldNotify(ShellSystemInsets oldWidget) =>
padding != oldWidget.padding;
}
/// Narrows a shell bar to the list pane while [split] (the tab shows its list
/// beside an open item), placing it at the pane's [alignment]; otherwise the
/// bar keeps the whole width it is given. The bar keeps its place in the tree
/// either way, so a split never remounts it.
class ListPaneWidth extends StatelessWidget {
const ListPaneWidth({
super.key,
required this.split,
required this.alignment,
this.preferredWidth,
required this.child,
});
final bool split;
/// The list width the operator dragged the divider to, null for the
/// default policy; see [listDetailListWidth].
final double? preferredWidth;
final AlignmentGeometry alignment;
final Widget child;
@override
Widget build(BuildContext context) => LayoutBuilder(
builder: (context, constraints) {
final width = split
? listDetailListWidth(
MediaQuery.sizeOf(context).width,
constraints.maxWidth,
preferredWidth,
)
: constraints.maxWidth;
return Align(
alignment: alignment,
heightFactor: 1,
child: SizedBox(width: width, child: child),
);
},
);
}
/// One body-priority policy for all destinations, derived from the full window
/// and actual available space after navigation. No fixed pixel pane widths.
///
/// Under the shell, the list keeps the shell's top bar (narrowed to the list
/// pane through [ShellPaneSplit], see [ListPaneWidth]) and the open item owns
/// the rest of the window: the detail starts at the top edge below the status
/// bar ([ShellSystemInsets]). The shell's tab bar stays at the bottom right,
/// over the detail pane, so the detail learns that bar's height plus
/// [kStackedBarGap] as its bottom padding: its own tabs (or the chat
/// composer) float above the shell's bar, never on it, and its content clears
/// both. Pages the item opens stay in its pane ([DetailPaneNavigator]).
class ListDetailPanes extends StatefulWidget {
const ListDetailPanes({
super.key,
required this.list,
required this.detail,
this.detailIdentity,
});
final Widget list;
final Widget detail;
/// Which item [detail] shows; selecting another item closes any page the
/// previous one opened in its pane.
final Object? detailIdentity;
@override
State<ListDetailPanes> createState() => _ListDetailPanesState();
}
class _ListDetailPanesState extends State<ListDetailPanes> {
// Outside a shell (no [ListPaneWidthsScope]) the divider still drags; the
// width lasts as long as the panes.
ListPaneWidths? _ownWidths;
@override
void dispose() {
_ownWidths?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final widths =
ListPaneWidthsScope.maybeOf(context) ??
(_ownWidths ??= ListPaneWidths(store: MemoryListPaneWidthStore()));
final key = ShellBarScope.maybeOf(context)?.destination.name ?? 'panes';
final media = MediaQuery.of(context);
final split = ShellBar.available(context);
return ShellPaneSplit(
child: ListenableBuilder(
listenable: widths,
builder: (context, _) => LayoutBuilder(
builder: (context, constraints) {
final window = media.size.width;
final available = constraints.maxWidth;
final preferred = widths.widthFor(key);
final listWidth = listDetailListWidth(window, available, preferred);
final bodyWidth = math.max(0.0, available - 1 - listWidth);
final bounds = listPaneWidthBounds(window, available);
Widget body = widget.detail;
Widget listPane = widget.list;
if (split) {
// Beside the list the item is not under the shell's top bar (it
// stays over the list pane): it keeps the system's own top
// inset, so its bar sits just below the status bar at the top
// edge. The shell's tab bar floats at the bottom right, over
// this pane; its height (the shell's bottom padding here) plus
// a gap lifts the item's tabs or composer above it.
final system = ShellSystemInsets.of(context);
body = MediaQuery(
data: media.copyWith(
padding: media.padding.copyWith(
top: system.top,
bottom: media.padding.bottom + kStackedBarGap,
),
),
child: PageTabsEdge(
edge: FloatingBarEdge.bottom,
child: DetailPaneNavigator(
identity: widget.detailIdentity,
child: body,
),
),
);
// The tab bar sits over the detail pane, never the list (the
// detail is at least half the window, wider than the bar), so
// the list clears only the system's bottom inset.
listPane = MediaQuery(
data: media.copyWith(
padding: media.padding.copyWith(bottom: system.bottom),
),
child: widget.list,
);
}
return Stack(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: SizedBox.expand(
key: const ValueKey('list-detail-list'),
child: Semantics(
container: true,
explicitChildNodes: true,
identifier: 'list-detail-list',
child: listPane,
),
),
),
const ListPaneDividerLine(),
SizedBox(
width: bodyWidth,
child: SizedBox.expand(
key: const ValueKey('list-detail-body'),
child: Semantics(
container: true,
explicitChildNodes: true,
identifier: 'list-detail-body',
child: body,
),
),
),
],
),
if (bounds != null)
PositionedDirectional(
start: listWidth + 0.5 - kListPaneDividerGrabWidth / 2,
top: 0,
bottom: 0,
width: kListPaneDividerGrabWidth,
child: ListPaneDivider(
width: listWidth,
min: bounds.min,
max: bounds.max,
onChanged: (value) => widths.preview(key, value),
onChangeEnd: () => widths.commit(key),
onReset: () => widths.reset(key),
),
),
],
);
},
),
),
);
}
}