From 0defe42ac1988e965400bcf75c68a6513e637820 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Fri, 23 Oct 2026 22:33:13 +0100 Subject: [PATCH] feat(app): section bodies sit on their own surface; the whole title strip toggles; no seam above a pinned title --- app/lib/ui/layout/section_heading.dart | 16 +- app/lib/ui/layout/sticky_section.dart | 167 ++++++++++++++------ app/test/ui/layout/sticky_section_test.dart | 15 ++ 3 files changed, 143 insertions(+), 55 deletions(-) diff --git a/app/lib/ui/layout/section_heading.dart b/app/lib/ui/layout/section_heading.dart index 87c855c6..834f83c5 100644 --- a/app/lib/ui/layout/section_heading.dart +++ b/app/lib/ui/layout/section_heading.dart @@ -9,12 +9,17 @@ import '../adaptive/host.dart'; class SectionHeadingStyle { const SectionHeadingStyle({ required this.background, + required this.body, required this.accent, required this.title, required this.line, }); final Color background; + + /// The surface under a section's content: between the page and the title, + /// so the content reads as belonging to its section. + final Color body; final Color accent; final TextStyle title; final Color line; @@ -23,8 +28,12 @@ class SectionHeadingStyle { if (usesCupertinoHost(context)) { final base = CupertinoTheme.of(context).textTheme.textStyle; return SectionHeadingStyle( - background: CupertinoColors.secondarySystemGroupedBackground - .resolveFrom(context), + background: CupertinoColors.tertiarySystemGroupedBackground.resolveFrom( + context, + ), + body: CupertinoColors.secondarySystemGroupedBackground.resolveFrom( + context, + ), accent: CupertinoTheme.of(context).primaryColor, title: base.copyWith( fontWeight: FontWeight.w700, @@ -35,7 +44,8 @@ class SectionHeadingStyle { } final scheme = Theme.of(context).colorScheme; return SectionHeadingStyle( - background: scheme.surfaceContainerHigh, + background: scheme.surfaceContainerHighest, + body: scheme.surfaceContainerLow, accent: scheme.primary, title: (Theme.of(context).textTheme.titleSmall ?? const TextStyle()) .copyWith(fontWeight: FontWeight.w700, color: scheme.onSurface), diff --git a/app/lib/ui/layout/sticky_section.dart b/app/lib/ui/layout/sticky_section.dart index f5d58761..6ae68190 100644 --- a/app/lib/ui/layout/sticky_section.dart +++ b/app/lib/ui/layout/sticky_section.dart @@ -52,14 +52,17 @@ class StickySection extends StatelessWidget { ), ), ), - // The content grows and shrinks under the pinned title. + // The content grows and shrinks under the pinned title, on its own + // surface with the title's accent continuing down its edge. SliverToBoxAdapter( child: ClipRect( child: AnimatedSize( duration: Motion.of(context, Motion.standard), curve: Motion.curve, alignment: Alignment.topCenter, - child: open ? body : const SizedBox(width: double.infinity), + child: open + ? _SectionBody(child: body) + : const SizedBox(width: double.infinity), ), ), ), @@ -96,61 +99,121 @@ class StickySectionTitle extends StatelessWidget { final style = color == null ? heading.title : heading.title.copyWith(color: color); - return DecoratedBox( - decoration: BoxDecoration( - color: heading.background, - border: Border( - left: BorderSide(color: heading.accent, width: 3), - bottom: BorderSide(color: heading.line, width: 0.5), - ), + final chevron = 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, ), - child: Padding( - padding: const EdgeInsetsDirectional.only(start: 13, end: 8), - child: Row( - children: [ - Expanded( - child: Semantics( - container: true, - header: true, - button: true, - expanded: open, - label: title, - excludeSemantics: true, - onTap: onToggle, - child: GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: onToggle, - child: Row( - children: [ - Expanded( - child: Text( - title, - style: style, - maxLines: 1, - overflow: TextOverflow.ellipsis, - ), - ), - 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, - ), - ), - ], - ), - ), + ); + final row = Padding( + padding: const EdgeInsetsDirectional.only(start: 13, end: 8), + child: Row( + children: [ + Expanded( + // The title is the section's heading and its toggle for + // assistive tech; the strip's own tap target is not announced. + child: Semantics( + container: true, + header: true, + button: true, + expanded: open, + label: title, + excludeSemantics: true, + onTap: onToggle, + child: Text( + title, + style: style, + maxLines: 1, + overflow: TextOverflow.ellipsis, ), ), - ...trailing, - ], - ), + ), + ...trailing, + ExcludeSemantics(child: chevron), + ], ), ); + final decoration = BoxDecoration( + color: heading.background, + border: Border( + left: BorderSide(color: heading.accent, width: 3), + bottom: BorderSide(color: heading.line, width: 0.5), + ), + ); + // The whole strip opens and closes the section; its own buttons (copy) + // still take their taps first. + final Widget strip = cupertino + ? GestureDetector( + behavior: HitTestBehavior.opaque, + excludeFromSemantics: true, + onTap: onToggle, + child: DecoratedBox(decoration: decoration, child: row), + ) + : Material( + color: heading.background, + child: Ink( + decoration: decoration, + child: InkWell( + onTap: onToggle, + excludeFromSemantics: true, + child: row, + ), + ), + ); + return Stack( + clipBehavior: Clip.none, + fit: StackFit.expand, + children: [ + // A few pixels of the title's colour above it: at fractional pixel + // ratios content scrolling under a pinned title could peek through. + Positioned( + left: 0, + right: 0, + top: -3, + height: 4, + child: ColoredBox(color: heading.background), + ), + MouseRegion(cursor: SystemMouseCursors.click, child: strip), + ], + ); + } +} + +/// A section's open content: its own surface, a faint continuation of the +/// title's accent, and room between the title and the first line. +class _SectionBody extends StatelessWidget { + const _SectionBody({required this.child}); + + final Widget child; + + @override + Widget build(BuildContext context) { + final heading = SectionHeadingStyle.of(context); + final decoration = BoxDecoration( + color: heading.body, + border: Border( + left: BorderSide( + color: heading.accent.withValues(alpha: 0.35), + width: 3, + ), + bottom: BorderSide(color: heading.line, width: 0.5), + ), + ); + final content = Padding( + padding: const EdgeInsets.only(top: 12, bottom: 4), + child: child, + ); + if (usesCupertinoHost(context)) { + return DecoratedBox(decoration: decoration, child: content); + } + // Rows inside paint their ripples on this surface. + return Material( + color: heading.body, + child: Ink(decoration: decoration, child: content), + ); } } diff --git a/app/test/ui/layout/sticky_section_test.dart b/app/test/ui/layout/sticky_section_test.dart index 17ed2e52..073b88cd 100644 --- a/app/test/ui/layout/sticky_section_test.dart +++ b/app/test/ui/layout/sticky_section_test.dart @@ -46,4 +46,19 @@ void main() { expect(find.text('line 40'), findsNothing); }, ); + + testWidgets('a tap anywhere on the title strip toggles the section', ( + tester, + ) async { + tester.view.physicalSize = const Size(390, 600); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + await tester.pumpWidget(const MaterialApp(home: Scaffold(body: _Host()))); + expect(find.text('line 0'), findsOneWidget); + // Empty space well right of the short title, left of the chevron. + final strip = tester.getRect(find.byType(StickySectionTitle)); + await tester.tapAt(Offset(strip.center.dx + 60, strip.center.dy)); + await tester.pumpAndSettle(); + expect(find.text('line 0'), findsNothing); + }); }