feat(chat): keep the rail and chat list beside the open chat on wide windows
This commit is contained in:
@@ -86,23 +86,32 @@ PageRoute<void> detailPageRoute(
|
||||
required AppDestination destination,
|
||||
required WidgetBuilder builder,
|
||||
}) {
|
||||
final page = _DetailPage(destination: destination, builder: builder);
|
||||
final page = DetailPane(destination: destination, builder: builder);
|
||||
return usesCupertinoHost(context)
|
||||
? CupertinoPageRoute<void>(builder: (_) => page)
|
||||
: MaterialPageRoute<void>(builder: (_) => page);
|
||||
}
|
||||
|
||||
class _DetailPage extends StatefulWidget {
|
||||
const _DetailPage({required this.destination, required this.builder});
|
||||
/// An open item's own bar over its content: what the content publishes
|
||||
/// through [ShellBar] (title and actions). As a pushed page it implies the
|
||||
/// platform's Back; inline beside a list ([implyBack] false) it shows none.
|
||||
class DetailPane extends StatefulWidget {
|
||||
const DetailPane({
|
||||
super.key,
|
||||
required this.destination,
|
||||
required this.builder,
|
||||
this.implyBack = true,
|
||||
});
|
||||
|
||||
final AppDestination destination;
|
||||
final WidgetBuilder builder;
|
||||
final bool implyBack;
|
||||
|
||||
@override
|
||||
State<_DetailPage> createState() => _DetailPageState();
|
||||
State<DetailPane> createState() => _DetailPaneState();
|
||||
}
|
||||
|
||||
class _DetailPageState extends State<_DetailPage> {
|
||||
class _DetailPaneState extends State<DetailPane> {
|
||||
final ShellBarRegistry _bar = ShellBarRegistry();
|
||||
|
||||
@override
|
||||
@@ -127,7 +136,7 @@ class _DetailPageState extends State<_DetailPage> {
|
||||
if (usesCupertinoHost(context)) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
automaticallyImplyLeading: true,
|
||||
automaticallyImplyLeading: widget.implyBack,
|
||||
middle: Text(title),
|
||||
trailing: actions.isEmpty
|
||||
? null
|
||||
@@ -138,7 +147,7 @@ class _DetailPageState extends State<_DetailPage> {
|
||||
}
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
automaticallyImplyLeading: true,
|
||||
automaticallyImplyLeading: widget.implyBack,
|
||||
title: Text(title),
|
||||
actions: actions,
|
||||
),
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
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),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user