import 'package:flutter/material.dart'; import '../../../ui/theme/app_design_tokens.dart'; import 'chat_stack_disc.dart'; /// The remove target's diameter: a little larger than an item, so it reads /// as a destination rather than another chat. const double kChatStackRemoveSize = kChatStackSlot + 8; /// How near its centre a finger counts as over the target: past its rim, /// as a thumb covers what it drags. const double kChatStackRemoveReach = kChatStackRemoveSize * .8; /// How much the target grows while a chat is over it. const double chatStackRemoveGrowth = 1.2; /// The "×" a dragged chat is dropped on to leave the open chats: a circle /// (the design's square under a flat design) that comes in when a drag /// starts and fills with the error colour while a chat is over it. It takes /// no input and says nothing to assistive technology: dropping is decided /// from the pointer's position, and the column's items offer the same /// removal as an action. /// /// Everything moves through transitions (fade, slide, scale, decoration), /// so a drag repaints it without rebuilding. class ChatStackRemoveTarget extends StatelessWidget { const ChatStackRemoveTarget({ super.key, required this.shown, required this.hover, required this.reduced, }); /// 0 hidden, 1 in place. final Animation shown; /// 0 idle, 1 with a chat over it. final Animation hover; /// Fades only: no slide in, no growth. final bool reduced; @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), ); final curve = shown.drive(CurveTween(curve: Curves.easeOutCubic)); Widget target = DecoratedBoxTransition( decoration: DecorationTween(begin: idle, end: hot).animate(hover), child: SizedBox.square( dimension: kChatStackRemoveSize, child: Stack( alignment: Alignment.center, children: [ Icon(Icons.close, color: scheme.onSurfaceVariant), FadeTransition( opacity: hover, child: Icon(Icons.close, color: scheme.onError), ), ], ), ), ); if (!reduced) { target = ScaleTransition( scale: Tween( begin: 1, end: chatStackRemoveGrowth, ).chain(CurveTween(curve: Curves.easeOutBack)).animate(hover), child: target, ); target = SlideTransition( position: Tween( begin: const Offset(0, .5), end: Offset.zero, ).animate(curve), child: target, ); } return IgnorePointer( child: ExcludeSemantics( child: FadeTransition(opacity: curve, child: target), ), ); } }