Files
pipelines/app/lib/shell/list_detail.dart
T
alan 885234e0e4 Cap the list pane at 440 px beside an open item
On very wide windows (a 4K monitor) the list took 40% of the window; past
440 px the extra width now goes to the open item. Fold and laptop widths
keep the 60/40 split.
2026-11-02 16:14:50 +00:00

219 lines
7.9 KiB
Dart

import 'dart:math' as math;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../ui/adaptive/floating_bar_layout.dart';
import '../ui/adaptive/host.dart';
import 'detail_pane_navigator.dart';
import 'shell_bar.dart';
/// At least this wide, a destination keeps its list beside the open item
/// (with the destination rail) instead of pushing the item as its own page.
const double kListDetailMinWidth = 600;
const double _bodyWindowTarget = 0.6;
const double _bodyWindowMinimum = 0.5;
const double _bodyAvailableMaximum = 0.75;
/// The widest the list pane grows beside an open item: on a very wide window
/// (a 4K monitor) the extra width goes to the open item, not the list.
const double kListPaneMaxWidth = 440;
/// Whether the window at [context] shows list and detail side by side.
bool showsListBesideDetail(BuildContext context) =>
MediaQuery.sizeOf(context).width >= kListDetailMinWidth;
/// The open item's width beside a list, for a [window] this wide and
/// [available] width for both panes and their divider.
double listDetailBodyWidth(double window, double available) {
// Target 60% of the full window. Keep at least half for the body while
// leaving a flexible share for native list controls on tighter windows.
final requestedMinimum = window * _bodyWindowMinimum;
final minimum = available > requestedMinimum
? requestedMinimum
: available * _bodyWindowMinimum;
final maximum = math.max(minimum, available * _bodyAvailableMaximum);
final body = (window * _bodyWindowTarget).clamp(minimum, maximum);
// Past the list's cap, the open item takes the rest.
return math.max(body, available - 1 - kListPaneMaxWidth);
}
/// The list pane's width beside an open item (see [listDetailBodyWidth]),
/// one divider excluded.
double listDetailListWidth(double window, double available) =>
math.max(0, available - 1 - listDetailBodyWidth(window, available));
/// 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,
required this.child,
});
final bool split;
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,
)
: 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 StatelessWidget {
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
Widget build(BuildContext context) {
final divider = usesCupertinoHost(context)
? Container(
width: 1,
color: CupertinoColors.separator.resolveFrom(context),
)
: const VerticalDivider(width: 1);
final media = MediaQuery.of(context);
final split = ShellBar.available(context);
return ShellPaneSplit(
child: LayoutBuilder(
builder: (context, constraints) {
final bodyWidth = listDetailBodyWidth(
media.size.width,
constraints.maxWidth,
);
Widget body = detail;
Widget listPane = 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: 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: list,
);
}
return 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,
),
),
),
divider,
SizedBox(
width: bodyWidth,
child: SizedBox.expand(
key: const ValueKey('list-detail-body'),
child: Semantics(
container: true,
explicitChildNodes: true,
identifier: 'list-detail-body',
child: body,
),
),
),
],
);
},
),
);
}
}