From 1ebcfc9e57e1685fe75a0c2438ab297c8de2f0c9 Mon Sep 17 00:00:00 2001 From: Mathis Kirchner Date: Sun, 11 Jan 2026 17:21:05 +0100 Subject: [PATCH] implement animation --- .../views/main_menu/settings_view.dart | 73 +++++++++++++++---- 1 file changed, 60 insertions(+), 13 deletions(-) diff --git a/lib/presentation/views/main_menu/settings_view.dart b/lib/presentation/views/main_menu/settings_view.dart index 5814537..cab26ef 100644 --- a/lib/presentation/views/main_menu/settings_view.dart +++ b/lib/presentation/views/main_menu/settings_view.dart @@ -97,23 +97,14 @@ class _SettingsViewState extends State { title: '${loc.delete_all_data}?', content: loc.this_cannot_be_undone, actions: [ - TextButton( - style: TextButton.styleFrom( - splashFactory: NoSplash.splashFactory, - overlayColor: Colors.transparent, - ), + _PressableButton( onPressed: () => Navigator.of(context).pop(false), - child: Text(loc.cancel, style: const TextStyle(color: CustomTheme.textColor),), + child: Text(loc.cancel, style: const TextStyle(color: CustomTheme.textColor)), ), - TextButton( - style: TextButton.styleFrom( - splashFactory: NoSplash.splashFactory, - overlayColor: Colors.transparent, - ), + _PressableButton( onPressed: () => Navigator.of(context).pop(true), - child: Text(loc.delete, style: TextStyle(color: CustomTheme.secondaryColor),), + child: Text(loc.delete, style: TextStyle(color: CustomTheme.secondaryColor)), ), - ], ), ).then((confirmed) { @@ -227,3 +218,59 @@ class _SettingsViewState extends State { }); } } + +class _PressableButton extends StatefulWidget { + final VoidCallback onPressed; + final Widget child; + + const _PressableButton({required this.onPressed, required this.child}); + + @override + State<_PressableButton> createState() => _PressableButtonState(); +} + +class _PressableButtonState extends State<_PressableButton> { + 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: Padding( + padding: const EdgeInsets.all(8.0), + child: widget.child, + ), + ), + ), + ); + } +} + + +/* + TextButton( + style: TextButton.styleFrom( + splashFactory: NoSplash.splashFactory, + overlayColor: Colors.transparent, + ), + onPressed: () => Navigator.of(context).pop(false), + child: Text(loc.cancel, style: const TextStyle(color: CustomTheme.textColor),), + ), + TextButton( + style: TextButton.styleFrom( + splashFactory: NoSplash.splashFactory, + overlayColor: Colors.transparent, + ), + onPressed: () => Navigator.of(context).pop(true), + child: Text(loc.delete, style: TextStyle(color: CustomTheme.secondaryColor),), + ), + */