53 lines
1.6 KiB
Dart
53 lines
1.6 KiB
Dart
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;
|
|
|
|
/// The list pane's share of a two-pane window, bounded so neither the rows
|
|
/// nor the open item become unusably narrow.
|
|
const double _listFraction = 0.36;
|
|
const double _listMinWidth = 280;
|
|
const double _listMaxWidth = 400;
|
|
|
|
/// Whether the window at [context] shows list and detail side by side.
|
|
bool showsListBesideDetail(BuildContext context) =>
|
|
MediaQuery.sizeOf(context).width >= kListDetailMinWidth;
|
|
|
|
/// A list beside its open item, split by the platform's own divider.
|
|
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 width = (constraints.maxWidth * _listFraction).clamp(
|
|
_listMinWidth,
|
|
_listMaxWidth,
|
|
);
|
|
return Row(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
SizedBox(width: width, child: list),
|
|
divider,
|
|
Expanded(child: detail),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|