import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import '../../../ui/theme/app_design_tokens.dart'; import 'chat_stack_disc.dart'; import 'chat_stack_drag.dart'; /// Lifts [child] for a drag after a short hold ([chatStackLiftDelay]); a /// quicker tap still reaches [child]'s own tap. Null callbacks leave the /// child alone. class ChatStackDragHandle extends StatelessWidget { const ChatStackDragHandle({ super.key, required this.child, this.onStart, this.onMove, this.onEnd, this.onCancel, }); final Widget child; final VoidCallback? onStart; final ValueChanged? onMove; final VoidCallback? onEnd; final VoidCallback? onCancel; @override Widget build(BuildContext context) { if (onStart == null) return child; return RawGestureDetector( // The items offer moving and removing as semantic actions instead. excludeFromSemantics: true, gestures: { LongPressGestureRecognizer: GestureRecognizerFactoryWithHandlers( () => LongPressGestureRecognizer( duration: chatStackLiftDelay, debugOwner: this, ), (recognizer) { recognizer ..onLongPressStart = ((_) => onStart?.call()) ..onLongPressMoveUpdate = onMove ..onLongPressEnd = ((_) => onEnd?.call()) ..onLongPressCancel = onCancel; }, ), }, child: child, ); } } /// A disc's ink and focus: the splash is drawn over the disc (the disc is /// opaque, so ink under it would never show), in the design's shape. class ChatStackTappable extends StatelessWidget { const ChatStackTappable({ super.key, required this.child, required this.onTap, this.autofocus = false, }); final Widget child; final VoidCallback onTap; final bool autofocus; @override Widget build(BuildContext context) { final shape = chatStackShape(AppDesignTokens.of(context)); return Stack( children: [ child, Positioned.fill( child: Padding( padding: const EdgeInsets.all( (kChatStackSlot - kChatStackDisc) / 2, ), child: Material( type: MaterialType.transparency, shape: shape, clipBehavior: Clip.antiAlias, child: InkWell( autofocus: autofocus, excludeFromSemantics: true, customBorder: shape, onTap: onTap, ), ), ), ), ], ); } }