a5912d9a1e
Keep the public cupertino parameters for existing callers while making the layout widgets and focused tests Material-only. Remove unreachable Cupertino imports, helpers, widgets, and test variants without changing the Material path.
363 lines
12 KiB
Dart
363 lines
12 KiB
Dart
import 'package:flutter/material.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');
|
|
|
|
/// The app's one list row (runs, pipelines, chats, search results,
|
|
/// schedules).
|
|
///
|
|
/// 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`); [emphasized]
|
|
/// marks unread/attention (a heavier title and an accent time). Rows ripple.
|
|
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;
|
|
|
|
/// Ignored: rows are always Material. Kept so existing callers compile.
|
|
final bool? cupertino;
|
|
|
|
/// The faint tint an unselected row with [accent] wears over the list.
|
|
/// The [cupertino] argument is ignored; the tint is always Material.
|
|
static Color? tintFor(
|
|
BuildContext context,
|
|
Color? accent, {
|
|
required bool cupertino,
|
|
}) => accent?.withValues(
|
|
alpha: Theme.of(context).brightness == Brightness.dark ? 0.12 : 0.07,
|
|
);
|
|
|
|
/// The open row's fill. The [cupertino] argument is ignored; the fill is
|
|
/// always Material `secondaryContainer`.
|
|
static Color selectedColor(BuildContext context, {required bool cupertino}) =>
|
|
Theme.of(context).colorScheme.secondaryContainer;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final styles = _RowStyles.of(
|
|
context,
|
|
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: false);
|
|
final surface = 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: 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 selected,
|
|
required bool emphasized,
|
|
}) {
|
|
final weight = emphasized ? FontWeight.w700 : FontWeight.w600;
|
|
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;
|
|
}
|