diff --git a/app/lib/ui/adaptive/segmented_bar.dart b/app/lib/ui/adaptive/segmented_bar.dart index ce9dea59..3eda670b 100644 --- a/app/lib/ui/adaptive/segmented_bar.dart +++ b/app/lib/ui/adaptive/segmented_bar.dart @@ -157,6 +157,12 @@ class SegmentedBar extends StatefulWidget class _SegmentedBarState extends State { bool _expanded = false; + /// The expanded title is drawn in the overlay, anchored to the collapsed + /// pill: drawn inside the bar it would overflow the bar's bounds, where + /// its pipeline action could be seen but not tapped. + final _titleLink = LayerLink(); + final _expandedTitle = OverlayPortalController(); + @override void didUpdateWidget(covariant SegmentedBar oldWidget) { super.didUpdateWidget(oldWidget); @@ -167,6 +173,10 @@ class _SegmentedBarState extends State { } void _toggleTitle() { + // The portal stays attached once used and draws nothing while + // collapsed, so collapsing on a new run (during a rebuild) needs no + // overlay call. + if (!_expandedTitle.isShowing) _expandedTitle.show(); setState(() => _expanded = !_expanded); } @@ -240,35 +250,35 @@ class _SegmentedBarState extends State { ), ), ) + : showTitle && !widget.expandableTitle + ? titlePill(false) : showTitle - ? Align( - alignment: AlignmentDirectional.centerStart, - widthFactor: _expanded && widget.expandableTitle - ? null - : 1, - child: ConstrainedBox( - constraints: _expanded && widget.expandableTitle - ? BoxConstraints(minWidth: constraints.maxWidth) - : const BoxConstraints(), - child: Stack( - clipBehavior: Clip.none, - children: [ - ExcludeSemantics( - excluding: _expanded && widget.expandableTitle, - child: titlePill(false), - ), - if (_expanded && widget.expandableTitle) - Positioned( + ? LayoutBuilder( + builder: (context, titleSpace) => OverlayPortal( + controller: _expandedTitle, + overlayChildBuilder: (context) => + !(_expanded && widget.expandableTitle) + ? const SizedBox.shrink() + : Positioned( top: 0, left: 0, - child: ConstrainedBox( - constraints: BoxConstraints( - maxWidth: constraints.maxWidth, + child: CompositedTransformFollower( + link: _titleLink, + showWhenUnlinked: false, + child: ConstrainedBox( + constraints: BoxConstraints( + maxWidth: titleSpace.maxWidth, + ), + child: titlePill(true), ), - child: titlePill(true), ), ), - ], + child: CompositedTransformTarget( + link: _titleLink, + child: ExcludeSemantics( + excluding: _expanded && widget.expandableTitle, + child: titlePill(false), + ), ), ), )