Files
pipelines/app/lib/ui/layout/app_list_row.dart
T
alan eea1361980 Grow the tapped chat row into the chat page on phones
Replace the identity-avatar Hero with a container transform: the row's
surface, tint and edge marker morph into the full page while the content
cross-fades, and Back, the Cupertino edge swipe or Android predictive back
shrink the page into the open chat's row. Reduced motion or a row off
screen fades instead; wide layouts are unchanged.
2026-11-10 03:11:05 +00:00

459 lines
16 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../adaptive/host.dart';
import 'app_list_avatar.dart';
/// Below this row width (a list pane squeezed beside its detail) a row is
/// compact: it keeps its avatar (a run's status) and its menu, so no row
/// loses its state or its actions, and moves the time under the subtitle,
/// leaving the title the line's width.
const double kAppListRowCompactWidth = 280;
/// Below this row width (narrower than any list pane, as in a row squeezed
/// by its host) the avatar and the menu would leave the text no room, so the
/// row drops them rather than overflow.
const double kAppListRowMinimalWidth = 160;
/// The rows' horizontal inset and the gap after the avatar.
const double kAppListRowInset = 16;
const double _avatarGap = 14;
const double _compactAvatarGap = 8;
/// The rows' vertical breathing room: the padding above and below the
/// content and the gap between the title and the lines under it. Rows stay
/// content-driven; these only space them out so they are easier to hit.
const double kAppListRowVerticalPadding = 13;
const double _lineGap = 4;
/// Keys on a row's highlight surface and inset divider, for tests.
const appListRowSurfaceKey = ValueKey<String>('app-list-row-surface');
const appListRowDividerKey = ValueKey<String>('app-list-row-divider');
const appListRowAccentKey = ValueKey<String>('app-list-row-accent');
bool _darkSurface(BuildContext context, bool cupertino) => cupertino
? CupertinoTheme.brightnessOf(context) == Brightness.dark
: Theme.of(context).brightness == Brightness.dark;
/// The app's one list row (runs, pipelines, chats, search results,
/// schedules), on both hosts.
///
/// Layout: [leading] (an [AppListAvatar]), then a bold one-line [title] with
/// the [time] at its trailing edge, then one muted [subtitle] line (with an
/// optional [subtitleLeading] dot/prefix and [subtitleTrailing] mark), then
/// the optional [menu] (an `AppOverflowMenu`). A row in a multi-select list
/// puts its checkbox in [selectionControl], which leads the row. A compact
/// row (narrower than [compactWidth]) keeps all of these and shows the time
/// on a line of its own under the subtitle. An inset hairline [divider]
/// under the text column separates rows. Nothing has a fixed height: the row
/// grows with text scaling and every line ellipsises.
///
/// [selected] paints the open row (Material `secondaryContainer`, Cupertino
/// `tertiarySystemFill`); [emphasized] marks unread/attention (a heavier
/// title and an accent time). Material rows ripple; Cupertino rows highlight
/// while pressed, like a native table cell.
class AppListRow extends StatelessWidget {
const AppListRow({
super.key,
required this.title,
this.leading,
this.time,
this.timeWidget,
this.subtitle,
this.compactSubtitle,
this.subtitleLeading,
this.subtitleTrailing,
this.menu,
this.onTap,
this.onLongPress,
this.selectionControl,
this.tapKey,
this.selected = false,
this.selectedFill,
this.emphasized = false,
this.divider = true,
this.compactWidth = kAppListRowCompactWidth,
this.cupertino,
this.accent,
this.showAccentBorder = true,
});
/// The item's own colour (a chat's highlight): a bar on the row's leading
/// edge and a faint tint under an unselected row. The selected fill still
/// marks the open row, so the two never read as one another.
final Color? accent;
/// Optional feature-specific selection surface, retaining selection semantics.
final Color? selectedFill;
/// Retain identity tint while a feature supplies its own visibility marker.
final bool showAccentBorder;
final Widget title;
final Widget? leading;
final String? time;
final Widget? timeWidget;
final Widget? subtitle;
/// Replaces [subtitle] in a compact row, which has less room for facts.
final Widget? compactSubtitle;
final Widget? subtitleLeading;
final Widget? subtitleTrailing;
final Widget? menu;
final VoidCallback? onTap;
/// A touch long-press on the row (for example, entering a select mode).
final VoidCallback? onLongPress;
/// A checkbox leading the row in a multi-select list.
final Widget? selectionControl;
/// Placed on the tap target ([InkWell] / [GestureDetector]).
final Key? tapKey;
final bool selected;
final bool emphasized;
final bool divider;
final double compactWidth;
/// Overrides the host detection (some features pick a style per platform).
final bool? cupertino;
/// The faint tint an unselected row with [accent] wears over the list.
static Color? tintFor(
BuildContext context,
Color? accent, {
required bool cupertino,
}) =>
accent?.withValues(alpha: _darkSurface(context, cupertino) ? 0.12 : 0.07);
/// The open row's fill on each host.
static Color selectedColor(BuildContext context, {required bool cupertino}) =>
cupertino
? CupertinoColors.tertiarySystemFill.resolveFrom(context)
: Theme.of(context).colorScheme.secondaryContainer;
@override
Widget build(BuildContext context) {
final cupertino = this.cupertino ?? usesCupertinoHost(context);
final styles = _RowStyles.of(
context,
cupertino: cupertino,
selected: selected,
emphasized: emphasized,
);
return Semantics(
container: true,
selected: selected,
button: onTap != null,
child: LayoutBuilder(
builder: (context, constraints) {
final compact = constraints.maxWidth < compactWidth;
final minimal = constraints.maxWidth < kAppListRowMinimalWidth;
final showLeading = leading != null && !minimal;
final showMenu = menu != null && !minimal;
final start = compact ? 12.0 : kAppListRowInset;
final avatarGap = compact ? _compactAvatarGap : _avatarGap;
final content = Padding(
padding: EdgeInsetsDirectional.only(
start: start,
end: showMenu ? 4 : kAppListRowInset,
top: kAppListRowVerticalPadding,
bottom: kAppListRowVerticalPadding,
),
child: Row(
children: [
if (selectionControl case final control?)
Padding(
padding: const EdgeInsetsDirectional.only(end: 8),
child: control,
),
if (showLeading)
Padding(
padding: EdgeInsetsDirectional.only(end: avatarGap),
child: leading,
),
Expanded(child: _text(styles, compact)),
if (showMenu)
Padding(
padding: const EdgeInsetsDirectional.only(start: 4),
child: menu,
),
],
),
);
final tint = tintFor(context, accent, cupertino: cupertino);
final surface = cupertino
? _CupertinoRowSurface(
tapKey: tapKey,
onTap: onTap,
onLongPress: onLongPress,
selected: selected,
tint: tint,
selectedFill: selectedFill,
child: content,
)
: Material(
key: appListRowSurfaceKey,
color: selected
? selectedFill ?? selectedColor(context, cupertino: false)
: tint ?? Colors.transparent,
child: InkWell(
key: tapKey,
onTap: onTap,
onLongPress: onLongPress,
child: content,
),
);
// The colour bar runs the row's whole height, divider included, and
// the tint fills the divider's inset too, so coloured rows read as
// one band each.
Widget marked(Widget row) => accent == null || !showAccentBorder
? row
: DecoratedBox(
key: appListRowAccentKey,
position: DecorationPosition.foreground,
decoration: BoxDecoration(
border: BorderDirectional(
start: BorderSide(color: accent!, width: 4),
),
),
child: row,
);
if (!divider) return marked(surface);
// The divider stays under the text column; a checkbox's width is
// not known here, so a selectable row's divider starts at the inset.
final textStart = selectionControl != null
? start
: start + (showLeading ? kAppListAvatarSize + avatarGap : 0);
final line = Padding(
padding: EdgeInsetsDirectional.only(start: textStart),
child: SizedBox(
key: appListRowDividerKey,
height: cupertino
? 1 / MediaQuery.devicePixelRatioOf(context)
: 1,
child: ColoredBox(color: styles.divider),
),
);
return marked(
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
surface,
if (tint != null && !selected)
ColoredBox(color: tint, child: line)
else
line,
],
),
);
},
),
);
}
/// The time, one ellipsised line in the time style, or null without one.
Widget? _time(_RowStyles styles) {
if (timeWidget == null && (time == null || time!.isEmpty)) return null;
return timeWidget == null
? Text(
time!,
style: styles.time,
maxLines: 1,
overflow: TextOverflow.ellipsis,
)
: DefaultTextStyle(
style: styles.time,
maxLines: 1,
overflow: TextOverflow.ellipsis,
child: timeWidget!,
);
}
Widget _text(_RowStyles styles, bool compact) {
final line = compact ? (compactSubtitle ?? subtitle) : subtitle;
final time = _time(styles);
final titleLine = LayoutBuilder(
// The time keeps at most 40% of the line, so very large text in a
// narrow row ellipsises instead of overflowing.
builder: (context, constraints) => Row(
children: [
Expanded(
child: DefaultTextStyle(
style: styles.title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
child: title,
),
),
if (!compact && time != null)
ConstrainedBox(
constraints: BoxConstraints(maxWidth: constraints.maxWidth * 0.4),
child: Padding(
padding: const EdgeInsetsDirectional.only(start: 8),
child: time,
),
),
],
),
);
// A compact row has no room beside its title: the time takes a line of
// its own under the subtitle.
final timeLine = compact ? time : null;
if (line == null && subtitleLeading == null && subtitleTrailing == null) {
if (timeLine == null) return titleLine;
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
titleLine,
const SizedBox(height: _lineGap),
timeLine,
],
);
}
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
titleLine,
const SizedBox(height: _lineGap),
Row(
children: [
if (subtitleLeading != null)
Padding(
padding: const EdgeInsetsDirectional.only(end: 6),
child: subtitleLeading,
),
Expanded(
child: DefaultTextStyle(
style: styles.subtitle,
maxLines: 1,
overflow: TextOverflow.ellipsis,
child: line ?? const SizedBox.shrink(),
),
),
if (subtitleTrailing != null)
Padding(
padding: const EdgeInsetsDirectional.only(start: 8),
child: subtitleTrailing,
),
],
),
?timeLine,
],
);
}
}
/// The row's text styles, from the host's own type scale.
class _RowStyles {
const _RowStyles(this.title, this.subtitle, this.time, this.divider);
factory _RowStyles.of(
BuildContext context, {
required bool cupertino,
required bool selected,
required bool emphasized,
}) {
final weight = emphasized ? FontWeight.w700 : FontWeight.w600;
if (cupertino) {
final theme = CupertinoTheme.of(context);
final base = theme.textTheme.textStyle;
final muted = CupertinoColors.secondaryLabel.resolveFrom(context);
final small = base.copyWith(fontSize: 15, color: muted);
return _RowStyles(
base.copyWith(fontWeight: weight, letterSpacing: 0),
small,
small.copyWith(
color: emphasized ? theme.primaryColor : muted,
fontWeight: emphasized ? FontWeight.w600 : null,
),
CupertinoColors.separator.resolveFrom(context),
);
}
final theme = Theme.of(context);
final scheme = theme.colorScheme;
final text = theme.textTheme;
final muted = scheme.onSurfaceVariant;
return _RowStyles(
(text.titleMedium ?? const TextStyle()).copyWith(
fontWeight: weight,
letterSpacing: 0,
color: selected ? scheme.onSecondaryContainer : scheme.onSurface,
),
(text.bodyMedium ?? const TextStyle()).copyWith(color: muted),
(text.bodySmall ?? const TextStyle()).copyWith(
color: emphasized ? scheme.primary : muted,
fontWeight: emphasized ? FontWeight.w600 : null,
),
scheme.outlineVariant,
);
}
final TextStyle title;
final TextStyle subtitle;
final TextStyle time;
final Color divider;
}
/// A Cupertino table cell: highlights while pressed, tinted while selected.
class _CupertinoRowSurface extends StatefulWidget {
const _CupertinoRowSurface({
required this.tapKey,
required this.onTap,
required this.selected,
this.onLongPress,
this.tint,
this.selectedFill,
required this.child,
});
/// The unselected row's tint, transparent when null.
final Color? tint;
final Color? selectedFill;
final Key? tapKey;
final VoidCallback? onTap;
final VoidCallback? onLongPress;
final bool selected;
final Widget child;
@override
State<_CupertinoRowSurface> createState() => _CupertinoRowSurfaceState();
}
class _CupertinoRowSurfaceState extends State<_CupertinoRowSurface> {
bool _pressed = false;
void _press(bool value) {
if (_pressed != value) setState(() => _pressed = value);
}
@override
Widget build(BuildContext context) {
final color = _pressed
? CupertinoColors.systemGrey4.resolveFrom(context)
: widget.selected
? widget.selectedFill ??
AppListRow.selectedColor(context, cupertino: true)
: widget.tint ?? const Color(0x00000000);
final enabled = widget.onTap != null;
return GestureDetector(
key: widget.tapKey,
behavior: HitTestBehavior.opaque,
onTap: widget.onTap,
onLongPress: widget.onLongPress,
onTapDown: enabled ? (_) => _press(true) : null,
onTapUp: enabled ? (_) => _press(false) : null,
onTapCancel: enabled ? () => _press(false) : null,
child: ColoredBox(
key: appListRowSurfaceKey,
color: color,
child: widget.child,
),
);
}
}