import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../../ui/adaptive/host.dart'; import '../../../ui/motion/quick_switch_effect.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 pose = quickSwitchPose( motion.style, motion.isAnimating ? motion.progress : 1, outgoing: outgoing, ); final shadow = usesCupertinoHost(context) ? CupertinoColors.black : Theme.of(context).shadowColor; final surface = usesCupertinoHost(context) ? CupertinoTheme.of(context).scaffoldBackgroundColor : Theme.of(context).colorScheme.surface; return LayoutBuilder( builder: (context, constraints) => Opacity( opacity: pose.opacity, child: Transform( alignment: Alignment.center, transform: pose.transform(constraints.biggest), child: DecoratedBox( decoration: BoxDecoration( color: motion.isAnimating && !motion.isTape ? surface : null, boxShadow: [ BoxShadow( color: shadow.withValues(alpha: .24 * pose.shadow), blurRadius: 22 * pose.shadow, offset: Offset(0, 8 * pose.shadow), ), ], ), child: child, ), ), ), ); } }