fba3b924f1
A 300 ms hold lifts a chat in the open column; dragging opens a gap and dropping commits through ChatWorkspaceController.movePane, the pane order the server syncs. An x comes in at the bottom while dragging; dropping on it removes the chat with Undo, which restores its place. Escape, a cancelled pointer or a drop away from the column put it back. Move up, Move down and Remove are semantic actions. Repaint-only motion; reduced motion swaps at once. Also keep floating-layout tracking out of initState, and let the capture kit hold a press before a drag. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
216 lines
6.8 KiB
Dart
216 lines
6.8 KiB
Dart
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 the design's 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 casts none, and its avatar frames itself.
|
|
class ChatStackDisc extends StatelessWidget {
|
|
const ChatStackDisc({super.key, required this.child, this.ring, this.lift});
|
|
|
|
final Widget child;
|
|
|
|
/// The rim's colour when it marks the current chat; null for the surface.
|
|
final Color? ring;
|
|
|
|
/// While dragged (0 at rest, 1 lifted): a deeper shadow, or under a flat
|
|
/// design a frame in the primary colour.
|
|
final Animation<double>? lift;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final tokens = AppDesignTokens.of(context);
|
|
final scheme = Theme.of(context).colorScheme;
|
|
// A raised dark design lifts the disc a tone, as Material's dark
|
|
// elevation does, so the pile's layers read where a shadow cannot.
|
|
final dark = Theme.of(context).brightness == Brightness.dark;
|
|
final base = tokens.panelFill(
|
|
scheme,
|
|
dark ? scheme.surfaceContainerHighest : scheme.surface,
|
|
);
|
|
final ring = this.ring;
|
|
final shape = chatStackShape(tokens);
|
|
final rest = ShapeDecoration(
|
|
color: ring ?? base,
|
|
// A flat design's avatar frames itself; the rim stays bare.
|
|
shape: shape,
|
|
shadows: !tokens.flat ? chatStackShadows(scheme) : null,
|
|
);
|
|
final lift = this.lift;
|
|
return SizedBox.square(
|
|
dimension: kChatStackSlot,
|
|
child: Center(
|
|
child: chatStackLifted(
|
|
lift,
|
|
rest,
|
|
chatStackRaised(rest, tokens, scheme),
|
|
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),
|
|
),
|
|
];
|
|
|
|
/// A short, close shadow's lifted form: deeper and softer, as a card
|
|
/// picked up off the column.
|
|
List<BoxShadow> chatStackLiftShadows(ColorScheme scheme) => [
|
|
BoxShadow(
|
|
color: scheme.shadow.withValues(alpha: .20),
|
|
blurRadius: 8,
|
|
offset: const Offset(0, 4),
|
|
),
|
|
BoxShadow(
|
|
color: scheme.shadow.withValues(alpha: .14),
|
|
blurRadius: 22,
|
|
offset: const Offset(0, 12),
|
|
),
|
|
];
|
|
|
|
/// [rest] as a dragged item wears it: the lifted shadow, or under a flat
|
|
/// design (which casts none) a frame in the primary colour.
|
|
ShapeDecoration chatStackRaised(
|
|
ShapeDecoration rest,
|
|
AppDesignTokens tokens,
|
|
ColorScheme scheme,
|
|
) {
|
|
final shape = rest.shape;
|
|
return ShapeDecoration(
|
|
color: rest.color,
|
|
shape: tokens.flat && shape is OutlinedBorder
|
|
? shape.copyWith(side: BorderSide(color: scheme.primary, width: 1.5))
|
|
: shape,
|
|
shadows: tokens.flat ? null : chatStackLiftShadows(scheme),
|
|
);
|
|
}
|
|
|
|
/// [child] over [rest], or blending to [raised] as [lift] runs: repaints
|
|
/// only.
|
|
Widget chatStackLifted(
|
|
Animation<double>? lift,
|
|
ShapeDecoration rest,
|
|
ShapeDecoration raised, {
|
|
required Widget child,
|
|
}) => lift == null
|
|
? DecoratedBox(decoration: rest, child: child)
|
|
: DecoratedBoxTransition(
|
|
decoration: DecorationTween(begin: rest, end: raised).animate(lift),
|
|
child: child,
|
|
);
|
|
|
|
/// 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,
|
|
this.lift,
|
|
});
|
|
|
|
final String text;
|
|
final Color? color;
|
|
final bool emphasized;
|
|
|
|
/// While dragged, as [ChatStackDisc.lift].
|
|
final Animation<double>? lift;
|
|
|
|
@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,
|
|
);
|
|
final rest = ShapeDecoration(
|
|
color: fill,
|
|
shape: _labelShape(tokens),
|
|
shadows: tokens.flat ? null : chatStackShadows(scheme),
|
|
);
|
|
return chatStackLifted(
|
|
lift,
|
|
rest,
|
|
chatStackRaised(rest, tokens, scheme),
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
|
child: Text(
|
|
text,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
softWrap: false,
|
|
style: style,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
OutlinedBorder _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,
|
|
);
|
|
}
|
|
}
|