feat(chat): keep the rail and chat list beside the open chat on wide windows

This commit is contained in:
2026-10-24 14:31:24 +01:00
parent fb481ad740
commit c7852d27d1
9 changed files with 343 additions and 21 deletions
+45 -5
View File
@@ -1,7 +1,10 @@
import '../../shell/destination.dart';
import '../../shell/detail_page.dart';
import '../../shell/list_detail.dart';
import '../../ui/adaptive/host.dart';
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../core/api_gateway.dart';
@@ -165,7 +168,7 @@ class _ChatScreenState extends State<ChatScreen> {
}
}
/// The open chat is a real page above the main screen at every window width.
/// On a phone the open chat is a real page above the main screen.
final DetailPageHost _page = DetailPageHost();
@override
@@ -200,11 +203,13 @@ class _ChatScreenState extends State<ChatScreen> {
@override
Widget build(BuildContext context) {
final selected = _selected;
// Chats are real Navigator pages at every width. Do not swap a conversation
// into the home page and manually emulate Back on tablets/foldables.
// A phone opens a chat as a real Navigator page with stock Back. A wide
// window keeps the destination rail and the chat list beside the open
// chat, which has no Back: another row, `/close` or a route change swaps it.
final beside = showsListBesideDetail(context);
_page.sync(
context,
selected: selected != null,
selected: selected != null && !beside,
destination: AppDestination.chat,
onClosed: _back,
builder: (context) => selected == null
@@ -221,6 +226,41 @@ class _ChatScreenState extends State<ChatScreen> {
activeSessionId: selected,
publishShellBar: true,
);
return list;
if (!beside) return list;
return ListDetailPanes(
list: list,
detail: selected == null
? const _NoChatSelected()
: DetailPane(
key: const ValueKey('chat-detail-pane'),
destination: AppDestination.chat,
implyBack: false,
builder: (context) => _thread(selected, _back),
),
);
}
}
/// The open-chat pane before any chat is chosen.
class _NoChatSelected extends StatelessWidget {
const _NoChatSelected();
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
cupertino
? CupertinoIcons.chat_bubble_2
: Icons.chat_bubble_outline,
),
const SizedBox(height: 12),
const Text('Select a chat to open it here.'),
],
),
);
}
}
+16 -7
View File
@@ -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,
),
+52
View File
@@ -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),
],
);
},
);
}
}