From 0fb6208345772524613625bf7b1cdde9eba60256 Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Mon, 12 Jan 2026 17:23:34 +0100 Subject: [PATCH] Created new buttons for the main menu --- .../widgets/buttons/main_menu_button.dart | 98 +++++++++++++++++++ pubspec.yaml | 3 +- 2 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 lib/presentation/widgets/buttons/main_menu_button.dart diff --git a/lib/presentation/widgets/buttons/main_menu_button.dart b/lib/presentation/widgets/buttons/main_menu_button.dart new file mode 100644 index 0000000..9e6ed80 --- /dev/null +++ b/lib/presentation/widgets/buttons/main_menu_button.dart @@ -0,0 +1,98 @@ +import 'package:flutter/material.dart'; + +/// A button for the main menu with an optional icon and a press animation. +/// - [text]: The text of the button. +/// - [icon]: The icon of the button. +/// - [onPressed]: The callback to be invoked when the button is pressed. +class MainMenuButton extends StatefulWidget { + const MainMenuButton({ + super.key, + required this.text, + this.icon, + required this.onPressed, + }); + + /// The text of the button. + final String text; + + /// The icon of the button. + final IconData? icon; + + /// The callback to be invoked when the button is pressed. + final void Function() onPressed; + + @override + State createState() => _MainMenuButtonState(); +} + +class _MainMenuButtonState extends State + with SingleTickerProviderStateMixin { + late AnimationController _animationController; + late Animation _scaleAnimation; + + @override + void initState() { + super.initState(); + + _animationController = AnimationController( + duration: const Duration(milliseconds: 100), + vsync: this, + ); + + _scaleAnimation = Tween(begin: 1.0, end: 0.95).animate( + CurvedAnimation(parent: _animationController, curve: Curves.easeInOut), + ); + } + + @override + Widget build(BuildContext context) { + return ScaleTransition( + scale: _scaleAnimation, + child: GestureDetector( + onTapDown: (_) { + _animationController.forward(); + }, + onTapUp: (_) async { + await _animationController.reverse(); + if (mounted) { + widget.onPressed(); + } + }, + onTapCancel: () { + _animationController.reverse(); + }, + child: Container( + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(30), + ), + padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 15), + child: Row( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + if (widget.icon != null) ...[ + Icon(widget.icon, size: 28, color: Colors.black), + const SizedBox(width: 7), + ], + Text( + widget.text, + style: const TextStyle( + fontSize: 20, + fontWeight: FontWeight.bold, + color: Colors.black, + ), + ), + ], + ), + ), + ), + ); + } + + @override + void dispose() { + _animationController.dispose(); + super.dispose(); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index 1b033f2..a7a2df7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: game_tracker description: "Game Tracking App for Card Games" publish_to: 'none' -version: 0.0.1+149 +version: 0.0.1+153 environment: sdk: ^3.8.1 @@ -23,6 +23,7 @@ dependencies: flutter_localizations: sdk: flutter package_info_plus: ^9.0.0 + fluttericon: ^2.0.0 dev_dependencies: flutter_test: