import 'package:flutter/material.dart'; import '../ui/sessions/chat_awaiting.dart'; import 'chat_stack_disc.dart'; import 'chat_stack_entry.dart'; import 'chat_stack_pose.dart'; /// A group's pile is the collapsed stack's, this much smaller, so it keeps /// inside its slot. const double chatStackGroupPileScale = .88; /// How many of a group's chats its pile draws. const int chatStackGroupLayers = 3; /// A group in the open column: its first chats piled as the collapsed stack /// piles the open ones (smaller, turned), the chat on screen on top when it /// is in the group, and the waiting bell when any of them waits on the /// operator. Paint-only poses; nothing animates here. class ChatStackGroupPile extends StatelessWidget { const ChatStackGroupPile({ super.key, required this.entries, this.glow, this.ring, }); final List entries; /// The top layer's lifted look (dragged) or drop-target [ring] (0 to 1). final Animation? glow; final Color? ring; @override Widget build(BuildContext context) { final current = entries.indexWhere((entry) => entry.current); final top = current < 0 ? 0 : current; final shown = [ for (var depth = 0; depth < entries.length; depth++) entries[(top + depth) % entries.length], ].take(chatStackGroupLayers).toList(); final rtl = Directionality.of(context) == TextDirection.rtl; final waiting = entries.fold(0, (sum, e) => sum + e.awaitingOperator); return SizedBox.square( dimension: kChatStackSlot, child: Stack( clipBehavior: Clip.none, children: [ for (var depth = shown.length - 1; depth >= 0; depth--) ChatStackPoseTransition( progress: kAlwaysCompleteAnimation, from: _pose(depth, rtl), to: _pose(depth, rtl), child: ChatStackDisc( lift: depth == 0 ? glow : null, liftRing: ring, child: chatStackAvatar(shown[depth], cues: false), ), ), if (waiting > 0) PositionedDirectional( top: -4, end: -4, child: IgnorePointer(child: ChatAwaitingBadge(count: waiting)), ), ], ), ); } ChatStackPose _pose(int depth, bool rtl) { final layer = chatStackLayers[depth]; final pose = ChatStackPose( offset: layer.offset * chatStackGroupPileScale, turn: layer.turn, scale: layer.scale * chatStackGroupPileScale, ); return rtl ? pose.mirrored() : pose; } }