Chat stack: a floating pile of the open chats as phone chat navigation (WIP)

This commit is contained in:
2026-12-03 20:07:00 +00:00
parent ab7b0b2c8c
commit fd62df3815
19 changed files with 2066 additions and 48 deletions
@@ -0,0 +1,158 @@
import 'package:flutter/material.dart';
import '../../../ui/layout/app_list_avatar.dart';
import '../../../ui/theme/app_design_tokens.dart';
/// The square every stack item occupies: a touch target at least as large as
/// the platform's minimum.
const double kChatStackSlot = 48;
/// The disc behind an avatar: the avatar plus a rim on each side.
const double kChatStackDisc = kChatStackSlot - 4;
/// The vertical distance between neighbouring items of the open column.
const double kChatStackPitch = kChatStackSlot + 8;
/// The gap between an item's name label and its avatar.
const double kChatStackLabelGap = 10;
/// An opaque disc in the design's shape (a circle, or a framed square under a
/// flat design) that carries one avatar of the stack. The list avatar's fill
/// is translucent; the disc keeps stacked avatars from showing through each
/// other, and its rim separates them. A raised design drops a short shadow;
/// a flat one keeps its hairline frame instead.
class ChatStackDisc extends StatelessWidget {
const ChatStackDisc({
super.key,
required this.child,
this.ring,
this.shadow = true,
});
final Widget child;
/// The rim's colour when it marks the current chat; null for the surface.
final Color? ring;
/// Whether this disc may cast a shadow (a layer under another does not).
final bool shadow;
@override
Widget build(BuildContext context) {
final tokens = AppDesignTokens.of(context);
final scheme = Theme.of(context).colorScheme;
final base = tokens.panelFill(scheme, scheme.surface);
final ring = this.ring;
final shape = chatStackShape(tokens);
final frame = tokens.frameSide;
return SizedBox.square(
dimension: kChatStackSlot,
child: Center(
child: DecoratedBox(
decoration: ShapeDecoration(
color: ring ?? base,
shape: shape.copyWith(
side: ring == null && frame != null ? frame : BorderSide.none,
),
shadows: shadow && !tokens.flat ? chatStackShadows(scheme) : null,
),
child: SizedBox.square(
dimension: kChatStackDisc,
child: Center(
child: DecoratedBox(
// The avatar's own tint lands on an opaque face, so the
// colour reads the same as in the list.
decoration: ShapeDecoration(color: base, shape: shape),
child: SizedBox.square(
dimension: kAppListAvatarSize,
child: child,
),
),
),
),
),
),
);
}
}
/// A circle, or the design's rounded square when it is flat (as the list's
/// avatar draws itself).
OutlinedBorder chatStackShape(AppDesignTokens tokens) => tokens.flat
? RoundedRectangleBorder(borderRadius: tokens.corners(BorderRadius.zero))
: const CircleBorder();
/// A short, close shadow: enough to lift a layer off the one below without a
/// halo over the transcript.
List<BoxShadow> chatStackShadows(ColorScheme scheme) => [
BoxShadow(
color: scheme.shadow.withValues(alpha: .18),
blurRadius: 4,
offset: const Offset(0, 1),
),
BoxShadow(
color: scheme.shadow.withValues(alpha: .10),
blurRadius: 10,
offset: const Offset(0, 4),
),
];
/// The name beside an avatar in the open column: a small pill tinted with
/// the chat's colour over an opaque face, one line, ellipsised.
class ChatStackLabel extends StatelessWidget {
const ChatStackLabel({
super.key,
required this.text,
this.color,
this.emphasized = false,
});
final String text;
final Color? color;
final bool emphasized;
@override
Widget build(BuildContext context) {
final tokens = AppDesignTokens.of(context);
final theme = Theme.of(context);
final scheme = theme.colorScheme;
final base = tokens.panelFill(scheme, scheme.surfaceContainerHigh);
final color = this.color;
final dark = theme.brightness == Brightness.dark;
final fill = color == null
? base
: Color.alphaBlend(color.withValues(alpha: dark ? .22 : .14), base);
final style = (theme.textTheme.labelLarge ?? const TextStyle()).copyWith(
color: scheme.onSurface,
fontWeight: emphasized ? FontWeight.w700 : FontWeight.w500,
);
return DecoratedBox(
decoration: ShapeDecoration(
color: fill,
shape: _labelShape(tokens),
shadows: tokens.flat ? null : chatStackShadows(scheme),
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
child: Text(
text,
maxLines: 1,
overflow: TextOverflow.ellipsis,
softWrap: false,
style: style,
),
),
);
}
ShapeBorder _labelShape(AppDesignTokens tokens) {
final side = tokens.frameSide ?? BorderSide.none;
final r = tokens.radius;
return r == null
? StadiumBorder(side: side)
: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(r),
side: side,
);
}
}