Files
pipelines/app/lib/features/chat/stack/chat_stack_close_target.dart
T
alan 130c1e6708 Chat stack: the default, also on a wide phone or tablet; a close button where the pile was
Chat stack is now the default phone chat navigation (a stored choice is
kept), and on Android or iOS it stays on a wide layout (an unfolded
foldable) above the active pane, where floating is ignored too. When
expanded, the pile turns into a close button at its own spot and the
column rises above it; while a chat is dragged that button is the remove
target, replacing the separate x at the bottom. Chat widget tests start
on Quick switch (they run as Android); the stack's tests choose it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 21:47:57 +00:00

127 lines
4.0 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:flutter/material.dart';
import '../../../ui/theme/app_design_tokens.dart';
import 'chat_stack_disc.dart';
/// How near the close button's centre a dragged chat's pointer counts as
/// over it: a little past its rim, as a thumb covers what it drags, and
/// short of the first chat's slot a pitch above.
const double kChatStackRemoveReach = kChatStackSlot * .7;
/// How much the button grows while a dragged chat is over it.
const double chatStackRemoveGrowth = 1.2;
/// The open stack's close button, exactly where the pile was: the pile
/// turns into a "×" as the column rises above it, and a tap folds the
/// column back.
///
/// While a chat is dragged it is also the remove target: its "×" turns the
/// error colour ([armed]), and with the chat over it ([hover]) it grows and
/// fills with the error colour. Dropping there is decided from the
/// pointer's position, not by this widget.
///
/// Everything moves through transitions (fade, turn, scale, decoration), so
/// opening and dragging repaint it without rebuilding.
class ChatStackCloseTarget extends StatelessWidget {
const ChatStackCloseTarget({
super.key,
required this.open,
required this.armed,
required this.hover,
required this.reduced,
required this.onClose,
});
static const label = 'Close chats';
/// 0 folded (the pile shows), 1 open.
final Animation<double> open;
/// 0 at rest, 1 while a chat is dragged.
final Animation<double> armed;
/// 0 idle, 1 with a dragged chat over it.
final Animation<double> hover;
/// Fades only: no turn, no growth.
final bool reduced;
final VoidCallback onClose;
@override
Widget build(BuildContext context) {
final tokens = AppDesignTokens.of(context);
final scheme = Theme.of(context).colorScheme;
final dark = Theme.of(context).brightness == Brightness.dark;
final shape = chatStackShape(tokens);
final side = tokens.flat
? tokens.frameSide ?? BorderSide(color: scheme.outlineVariant)
: BorderSide.none;
final idle = ShapeDecoration(
color: tokens.panelFill(
scheme,
dark ? scheme.surfaceContainerHighest : scheme.surface,
),
shape: shape.copyWith(side: side),
shadows: tokens.flat ? null : chatStackShadows(scheme),
);
final hot = ShapeDecoration(
color: scheme.error,
shape: shape.copyWith(
side: tokens.flat ? side.copyWith(color: scheme.error) : side,
),
shadows: tokens.flat ? null : chatStackShadows(scheme),
);
Widget icon(Color color, Animation<double> opacity) => FadeTransition(
opacity: opacity,
child: Icon(Icons.close, color: color),
);
Widget button = DecoratedBoxTransition(
decoration: DecorationTween(begin: idle, end: hot).animate(hover),
child: SizedBox.square(
dimension: kChatStackDisc,
child: Stack(
alignment: Alignment.center,
children: [
icon(scheme.onSurfaceVariant, ReverseAnimation(armed)),
icon(scheme.error, armed),
icon(scheme.onError, hover),
],
),
),
);
final shown = open.drive(CurveTween(curve: Curves.easeOutCubic));
if (!reduced) {
button = ScaleTransition(
scale: Tween<double>(
begin: 1,
end: chatStackRemoveGrowth,
).chain(CurveTween(curve: Curves.easeOutBack)).animate(hover),
child: button,
);
// The pile's top avatar turns into the "×" a quarter turn.
button = RotationTransition(
turns: Tween<double>(begin: -.25, end: 0).animate(shown),
child: ScaleTransition(
scale: Tween<double>(begin: .6, end: 1).animate(shown),
child: button,
),
);
}
return Semantics(
container: true,
button: true,
label: label,
onTap: onClose,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
excludeFromSemantics: true,
onTap: onClose,
child: FadeTransition(
opacity: shown,
child: Center(child: button),
),
),
);
}
}