82 lines
2.8 KiB
Dart
82 lines
2.8 KiB
Dart
import 'dart:math' as math;
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../ui/adaptive/host.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;
|
|
|
|
/// Whether the window at [context] shows list and detail side by side.
|
|
bool showsListBesideDetail(BuildContext context) =>
|
|
MediaQuery.sizeOf(context).width >= kListDetailMinWidth;
|
|
|
|
/// One body-priority policy for all destinations, derived from the full window
|
|
/// and actual available space after navigation. No fixed pixel pane widths.
|
|
class ListDetailPanes extends StatelessWidget {
|
|
const ListDetailPanes({super.key, required this.list, required this.detail});
|
|
|
|
final Widget list;
|
|
final Widget detail;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final divider = usesCupertinoHost(context)
|
|
? Container(
|
|
width: 1,
|
|
color: CupertinoColors.separator.resolveFrom(context),
|
|
)
|
|
: const VerticalDivider(width: 1);
|
|
return LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
final window = MediaQuery.sizeOf(context).width;
|
|
// 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 = constraints.maxWidth > requestedMinimum
|
|
? requestedMinimum
|
|
: constraints.maxWidth * _bodyWindowMinimum;
|
|
final maximum = math.max(
|
|
minimum,
|
|
constraints.maxWidth * _bodyAvailableMaximum,
|
|
);
|
|
final bodyWidth = (window * _bodyWindowTarget).clamp(minimum, maximum);
|
|
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: list,
|
|
),
|
|
),
|
|
),
|
|
divider,
|
|
SizedBox(
|
|
width: bodyWidth,
|
|
child: SizedBox.expand(
|
|
key: const ValueKey('list-detail-body'),
|
|
child: Semantics(
|
|
container: true,
|
|
explicitChildNodes: true,
|
|
identifier: 'list-detail-body',
|
|
child: detail,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|