From 9365313c9215a5ad77f2a16b8c2c05f7dad03ad9 Mon Sep 17 00:00:00 2001 From: mathiskirchner Date: Wed, 19 Nov 2025 16:39:32 +0100 Subject: [PATCH] button not working --- .../views/main_menu/create_group_view.dart | 7 ++- .../widgets/custom_width_button.dart | 46 ++++++++++++++----- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/lib/presentation/views/main_menu/create_group_view.dart b/lib/presentation/views/main_menu/create_group_view.dart index 81d5e36..f43fc8d 100644 --- a/lib/presentation/views/main_menu/create_group_view.dart +++ b/lib/presentation/views/main_menu/create_group_view.dart @@ -1,4 +1,4 @@ -import 'package:flutter/material.dart'; +import 'package:flutter/material.dart' hide ButtonStyle; import 'package:game_tracker/core/custom_theme.dart'; import 'package:game_tracker/data/db/database.dart'; import 'package:game_tracker/data/dto/group.dart'; @@ -265,8 +265,8 @@ class _CreateGroupViewState extends State { ), CustomWidthButton( text: 'Create group', - disabledInfillColor: CustomTheme.boxColor, sizeRelativeToWidth: 0.95, + buttonStyle: ButtonStyle.secondary, onPressed: (_groupNameController.text.isEmpty || selectedPlayers.isEmpty) ? null @@ -277,14 +277,13 @@ class _CreateGroupViewState extends State { members: selectedPlayers, ), ); + if (!context.mounted) return; if (success) { _groupNameController.clear(); _searchBarController.clear(); selectedPlayers.clear(); - if (!mounted) return; Navigator.pop(context); } else { - if (!mounted) return; ScaffoldMessenger.of(context).showSnackBar( SnackBar( backgroundColor: CustomTheme.boxColor, diff --git a/lib/presentation/widgets/custom_width_button.dart b/lib/presentation/widgets/custom_width_button.dart index b0b9bd3..2a79d1b 100644 --- a/lib/presentation/widgets/custom_width_button.dart +++ b/lib/presentation/widgets/custom_width_button.dart @@ -7,45 +7,67 @@ class CustomWidthButton extends StatelessWidget { const CustomWidthButton({ super.key, required this.text, - this.disabledInfillColor, this.buttonStyle = ButtonStyle.primary, required this.sizeRelativeToWidth, - required this.onPressed, + this.onPressed, }); final String text; - final Color? disabledInfillColor; final double sizeRelativeToWidth; final VoidCallback? onPressed; final ButtonStyle buttonStyle; @override Widget build(BuildContext context) { + + final Color buttonBackgroundColor; + final Color disabledBackgroundColor; + final Color borderSideColor; + final Color disabledBorderSideColor; + final Color textcolor; + final Color disabledTextColor; + + + if(buttonStyle == ButtonStyle.primary){ + buttonBackgroundColor = CustomTheme.primaryColor; + disabledBackgroundColor = CustomTheme.primaryColor.withValues(alpha: 0.24); + borderSideColor = Colors.transparent; + disabledBorderSideColor = Colors.transparent; + textcolor = Colors.white; + disabledTextColor = Colors.white.withValues(alpha: 0.24); + } else{ + buttonBackgroundColor = Colors.transparent; + disabledBackgroundColor = Colors.transparent; + borderSideColor = CustomTheme.primaryColor.withValues(alpha: 0.6 ); + disabledBorderSideColor = Colors.transparent; + textcolor = CustomTheme.primaryColor; + disabledTextColor = CustomTheme.primaryColor.withValues(alpha: 0.24); + } + + return ElevatedButton( onPressed: onPressed, style: ElevatedButton.styleFrom( - disabledBackgroundColor: disabledInfillColor, + disabledBackgroundColor: disabledBackgroundColor, minimumSize: Size( MediaQuery.sizeOf(context).width * sizeRelativeToWidth, 60, ), - backgroundColor: buttonStyle == ButtonStyle.primary - ? CustomTheme.primaryColor - : CustomTheme.secondaryColor, + backgroundColor: buttonBackgroundColor, side: BorderSide( - color: buttonStyle == ButtonStyle.primary - ? CustomTheme.primaryColor - : CustomTheme.secondaryColor, + color: borderSideColor, width: 2, ), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)), ), child: Text( text, - style: const TextStyle( + style: TextStyle( fontWeight: FontWeight.w500, fontSize: 22, - color: Colors.white, + color: (onPressed == null) + ? disabledTextColor + : textcolor, ), ), );