feat(app): chat sections are clear collapsible dividers; closed chats start collapsed
This commit is contained in:
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user