import 'package:flutter/material.dart'; import 'package:game_tracker/core/custom_theme.dart'; /// A custom animated button widget that provides a scaling and opacity effect /// when pressed. This widget is designed to be used in dialogs or other UI /// components where a visually appealing button is required. /// /// Parameters: /// - [onPressed]: Callback function that is triggered when the button is pressed. /// - [child]: The child widget to be displayed inside the button, typically a text or icon. /// - [backgroundColor]: Optional background color for the button container. If null, uses the standard box color from CustomTheme. class AnimatedDialogButton extends StatefulWidget { const AnimatedDialogButton({ super.key, required this.onPressed, required this.child, this.backgroundColor, }); final VoidCallback onPressed; final Widget child; final Color? backgroundColor; @override State createState() => _AnimatedDialogButtonState(); } class _AnimatedDialogButtonState extends State { bool _isPressed = false; @override Widget build(BuildContext context) { return GestureDetector( onTapDown: (_) => setState(() => _isPressed = true), onTapUp: (_) => setState(() => _isPressed = false), onTapCancel: () => setState(() => _isPressed = false), onTap: widget.onPressed, child: AnimatedScale( scale: _isPressed ? 0.95 : 1.0, duration: const Duration(milliseconds: 100), child: AnimatedOpacity( opacity: _isPressed ? 0.6 : 1.0, duration: const Duration(milliseconds: 100), child: Container( decoration: widget.backgroundColor != null ? CustomTheme.standardBoxDecoration.copyWith( color: widget.backgroundColor, ) : CustomTheme.standardBoxDecoration, padding: const EdgeInsets.symmetric(horizontal: 26, vertical: 6), child: widget.child, ), ), ), ); } }