feat(app): chat sections are clear collapsible dividers; closed chats start collapsed

This commit is contained in:
2026-10-24 00:22:18 +01:00
parent d0b1c8e524
commit 1e55b8d2b3
16 changed files with 293 additions and 161 deletions
@@ -1,5 +1,5 @@
import '../../../../ui/layout/collapsible_list_section.dart';
import '../../../../ui/theme/app_theme.dart';
import '../../../../ui/layout/section_heading.dart';
import 'package:flutter/cupertino.dart';
import '../../../../core/api_gateway.dart';
@@ -58,23 +58,32 @@ class CupertinoSessionList extends StatelessWidget {
);
}
List<CupertinoListSection> _section(ChatSessionSection section) {
List<Widget> _section(ChatSessionSection section) {
final groups = groupChatSessions(section.sessions);
// Closed chats start folded away; the live ones start open.
return [
for (final group in groups)
CupertinoListSection.insetGrouped(
backgroundColor: AppColors.groupedBackground,
// Styled as a section divider, not as another chat row.
header: Builder(
builder: (context) => Text(
groups.length > 1
? '${section.title} · ${group.directory.isEmpty ? 'No directory' : group.directory}'
: section.title,
style: SectionHeadingStyle.of(context).title,
CollapsibleListSection(
key: ValueKey('chat-section-${section.title}'),
title: section.title,
count: section.sessions.length,
initiallyOpen: section.title != 'Closed',
children: [
for (final group in groups)
CupertinoListSection.insetGrouped(
backgroundColor: AppColors.groupedBackground,
header: groups.length > 1
? Text(
group.directory.isEmpty
? 'No directory'
: group.directory,
)
: null,
children: [
for (final session in group.sessions) ..._row(session),
],
),
),
children: [for (final session in group.sessions) ..._row(session)],
),
],
),
];
}
@@ -1,3 +1,4 @@
import '../../../../ui/layout/collapsible_list_section.dart';
import '../../../../ui/layout/section_heading.dart';
import 'package:flutter/material.dart';
@@ -63,14 +64,12 @@ class MaterialSessionList extends StatelessWidget {
Widget _section(BuildContext context, ChatSessionSection section) {
final groups = groupChatSessions(section.sessions);
final heading = SectionHeadingStyle.of(context);
return ExpansionTile(
// Styled as a section divider, not as another chat row.
title: Text(section.title, style: heading.title),
backgroundColor: heading.background.withValues(alpha: 0.35),
collapsedBackgroundColor: heading.background,
shape: Border(left: BorderSide(color: heading.accent, width: 3)),
collapsedShape: Border(left: BorderSide(color: heading.accent, width: 3)),
initiallyExpanded: true,
// Closed chats start folded away; the live ones start open.
return CollapsibleListSection(
key: ValueKey('chat-section-${section.title}'),
title: section.title,
count: section.sessions.length,
initiallyOpen: section.title != 'Closed',
children: [
for (final group in groups) ...[
if (groups.length > 1)
@@ -0,0 +1,98 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../adaptive/host.dart';
import '../motion/motion.dart';
import 'section_heading.dart';
/// A titled group in a list: a [SectionHeading] strip (bold title, count,
/// chevron) that reads as a divider, and opens or closes its rows on a tap.
class CollapsibleListSection extends StatefulWidget {
const CollapsibleListSection({
super.key,
required this.title,
required this.children,
this.count,
this.initiallyOpen = true,
});
final String title;
final int? count;
final bool initiallyOpen;
final List<Widget> children;
@override
State<CollapsibleListSection> createState() => _CollapsibleListSectionState();
}
class _CollapsibleListSectionState extends State<CollapsibleListSection> {
late bool _open = widget.initiallyOpen;
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
final muted = cupertino
? CupertinoColors.secondaryLabel.resolveFrom(context)
: Theme.of(context).colorScheme.onSurfaceVariant;
final heading = Semantics(
container: true,
header: true,
button: true,
expanded: _open,
label: widget.title,
excludeSemantics: true,
onTap: _toggle,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: _toggle,
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: SectionHeading(
title: widget.title,
minHeight: 44,
trailing: [
if (widget.count != null)
Padding(
padding: const EdgeInsetsDirectional.only(end: 6),
child: Text(
'${widget.count}',
style: TextStyle(color: muted),
),
),
AnimatedRotation(
turns: _open ? 0.5 : 0,
duration: Motion.of(context, Motion.standard),
curve: Motion.curve,
child: Icon(
cupertino ? CupertinoIcons.chevron_down : Icons.expand_more,
color: muted,
),
),
],
),
),
),
);
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(padding: const EdgeInsets.only(top: 8), child: heading),
ClipRect(
child: AnimatedSize(
duration: Motion.of(context, Motion.standard),
curve: Motion.curve,
alignment: Alignment.topCenter,
child: _open
? Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: widget.children,
)
: const SizedBox(width: double.infinity),
),
),
],
);
}
void _toggle() => setState(() => _open = !_open);
}