40e94cc3da
The four destination buttons move from the bottom right over the detail pane to the bottom of the list pane, centred in the (dragged) list width. The list now keeps the bar's height as bottom clearance; the detail pane clears only the system inset, so its tabs, the chat composer and the artifact actions sit at its bottom edge. Phone layout is unchanged. kStackedBarGap is gone with the stacked bars.
223 lines
7.9 KiB
Dart
223 lines
7.9 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 moves to the bottom of the
|
|
/// list pane, so the list learns that bar's height as its bottom padding and
|
|
/// the detail keeps its whole height: its own tabs (or the chat composer) sit
|
|
/// at its bottom edge, above the system inset only. 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;
|
|
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 of the list
|
|
// pane, not over this one, so the item clears only the
|
|
// system's bottom inset and its own tabs or composer sit at
|
|
// its bottom edge.
|
|
final system = ShellSystemInsets.of(context);
|
|
body = MediaQuery(
|
|
data: media.copyWith(
|
|
padding: media.padding.copyWith(
|
|
top: system.top,
|
|
bottom: system.bottom,
|
|
),
|
|
),
|
|
child: PageTabsEdge(
|
|
edge: FloatingBarEdge.bottom,
|
|
child: DetailPaneNavigator(
|
|
identity: widget.detailIdentity,
|
|
child: body,
|
|
),
|
|
),
|
|
);
|
|
// The list keeps the shell's bottom padding (the tab bar's
|
|
// height), so its last rows scroll clear of the bar.
|
|
}
|
|
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: widget.list,
|
|
),
|
|
),
|
|
),
|
|
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),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|