Files
pipelines/app/lib/ui/layout/app_list_avatar.dart
T
alan 3c56db37fd Share one list row across runs, pipelines, chat, search and schedules
AppListRow (Material + Cupertino) with avatar, bold title and trailing
time, one muted line, one overflow menu style, inset dividers, selected
and emphasised states and a compact mode. Pipelines get a legible initial
avatar, schedule rows shrink to two lines with Edit/Pause/Delete in an
overflow menu, and the shell chat list scrolls behind the bar.
2026-10-31 04:15:01 +00:00

133 lines
4.0 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../adaptive/host.dart';
/// The leading circle every list row uses, as large as a native contact
/// avatar ([CircleAvatar]'s default).
const double kAppListAvatarSize = 40;
/// A list row's leading identity: an icon or an initial on a tinted circle,
/// with an optional corner badge (a chat's activity indicator).
///
/// [foreground] colours the icon/initial; the circle is [background], or the
/// foreground at 14% when omitted, so a status colour reads as a soft tint.
class AppListAvatar extends StatelessWidget {
const AppListAvatar({
super.key,
required this.child,
this.foreground,
this.background,
this.badge,
});
/// The first character of [name] (or `?`), large and bold enough to read
/// at a glance in the circle.
factory AppListAvatar.initial(
String name, {
Key? key,
required Color color,
Widget? badge,
}) {
final trimmed = name.trimLeft();
final initial = trimmed.isEmpty
? '?'
: String.fromCharCode(trimmed.runes.first).toUpperCase();
return AppListAvatar(
key: key,
foreground: color,
badge: badge,
child: Text(initial),
);
}
final Widget child;
final Color? foreground;
final Color? background;
final Widget? badge;
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
final mark =
foreground ??
(cupertino
? CupertinoColors.secondaryLabel.resolveFrom(context)
: Theme.of(context).colorScheme.onSurfaceVariant);
final fill =
background ??
(foreground == null
? (cupertino
? CupertinoColors.systemGrey5.resolveFrom(context)
: Theme.of(context).colorScheme.surfaceContainerHighest)
: mark.withValues(alpha: 0.14));
final initialStyle =
(cupertino
? CupertinoTheme.of(context).textTheme.textStyle
: Theme.of(context).textTheme.titleMedium ?? const TextStyle())
.copyWith(
color: mark,
fontSize: 18,
fontWeight: FontWeight.w700,
height: 1,
);
final circle = SizedBox.square(
dimension: kAppListAvatarSize,
child: DecoratedBox(
decoration: BoxDecoration(color: fill, shape: BoxShape.circle),
child: Center(
// The glyph is identity, not reading text: it scales down to stay
// inside the circle under large text instead of overflowing it.
child: Padding(
padding: const EdgeInsets.all(8),
child: FittedBox(
fit: BoxFit.scaleDown,
child: IconTheme.merge(
data: IconThemeData(color: mark, size: 22),
child: DefaultTextStyle(style: initialStyle, child: child),
),
),
),
),
),
);
if (badge == null) return circle;
return Stack(
clipBehavior: Clip.none,
children: [
circle,
PositionedDirectional(end: -2, bottom: -2, child: badge!),
],
);
}
}
/// A small coloured dot that leads a row's subtitle (a latest-run state) or
/// trails it (unread). It follows text scaling and carries its own label.
class AppListStatusDot extends StatelessWidget {
const AppListStatusDot({
super.key,
required this.color,
this.semanticLabel,
this.size = 8,
});
final Color color;
final String? semanticLabel;
final double size;
@override
Widget build(BuildContext context) {
final dimension = MediaQuery.textScalerOf(context).scale(size);
final dot = DecoratedBox(
decoration: BoxDecoration(color: color, shape: BoxShape.circle),
child: SizedBox.square(dimension: dimension),
);
if (semanticLabel == null) return ExcludeSemantics(child: dot);
return Semantics(
label: semanticLabel,
child: ExcludeSemantics(child: dot),
);
}
}