import 'dart:math' as math; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../../ui/adaptive/host.dart'; import '../../../ui/motion/quick_switch_animation.dart'; import 'chat_pane_switch_motion.dart'; /// Perspective affects paint only. The retained chat keeps its real viewport /// and its scroll controllers, focus scope and draft throughout the exchange. class ChatSwitchCard extends StatelessWidget { const ChatSwitchCard({ super.key, required this.motion, required this.outgoing, required this.child, }); final ChatPaneSwitchMotion motion; final bool outgoing; final Widget child; @override Widget build(BuildContext context) { final lift = motion.isAnimating && motion.style == QuickSwitchAnimation.cardStack ? math.sin(math.pi * motion.progress) : 0.0; final direction = outgoing ? -1.0 : 1.0; final transform = Matrix4.identity() ..setEntry(3, 2, .0012 * lift) ..translateByDouble(0, 0, -(outgoing ? 90 : 40) * lift, 1) ..rotateY(direction * .22 * lift) ..rotateZ(direction * .035 * lift); final shadow = usesCupertinoHost(context) ? CupertinoColors.black : Theme.of(context).shadowColor; return Transform( alignment: Alignment.center, transform: transform, child: DecoratedBox( decoration: BoxDecoration( boxShadow: [ BoxShadow( color: shadow.withValues(alpha: .24 * lift), blurRadius: 22 * lift, offset: Offset(0, 8 * lift), ), ], ), child: child, ), ); } }