Files
game-tracker/lib/presentation/widgets/buttons/animated_dialog_button.dart
Mathis Kirchner 4019ed083f
Some checks failed
Pull Request Pipeline / lint (pull_request) Failing after 2m47s
Pull Request Pipeline / test (pull_request) Successful in 2m38s
add background color option to AnimatedDialogButton
2026-01-13 21:53:45 +01:00

58 lines
2.0 KiB
Dart

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<AnimatedDialogButton> createState() => _AnimatedDialogButtonState();
}
class _AnimatedDialogButtonState extends State<AnimatedDialogButton> {
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,
),
),
),
);
}
}