From 546a3e37174b4187e4e2d9c48b55e6bbba69f0d4 Mon Sep 17 00:00:00 2001 From: mathiskirchner Date: Sat, 22 Nov 2025 22:49:17 +0100 Subject: [PATCH 1/4] implemented feature to automatically add newly created player to selected players --- .../views/main_menu/create_group_view.dart | 85 +++++++++---------- 1 file changed, 39 insertions(+), 46 deletions(-) diff --git a/lib/presentation/views/main_menu/create_group_view.dart b/lib/presentation/views/main_menu/create_group_view.dart index c54369e..75fdb83 100644 --- a/lib/presentation/views/main_menu/create_group_view.dart +++ b/lib/presentation/views/main_menu/create_group_view.dart @@ -49,8 +49,7 @@ class _CreateGroupViewState extends State { @override void dispose() { _groupNameController.dispose(); - _searchBarController - .dispose(); // Listener entfernen und Controller aufräumen + _searchBarController.dispose(); super.dispose(); } @@ -123,12 +122,7 @@ class _CreateGroupViewState extends State { .trim() .isNotEmpty, onTrailingButtonPressed: () async { - addNewPlayerFromSearch( - context: context, - searchBarController: _searchBarController, - db: db, - loadPlayerList: loadPlayerList, - ); + addNewPlayerFromSearch(context: context); }, onChanged: (value) { setState(() { @@ -339,48 +333,47 @@ class _CreateGroupViewState extends State { ), ); } -} -/// Adds a new player to the database from the search bar input. -/// Shows a snackbar indicating success or failure. -/// [context] - BuildContext to show the snackbar. -/// [searchBarController] - TextEditingController of the search bar. -/// [db] - AppDatabase instance to interact with the database. -/// [loadPlayerList] - Function to reload the player list after adding. -void addNewPlayerFromSearch({ - required BuildContext context, - required TextEditingController searchBarController, - required AppDatabase db, - required Function loadPlayerList, -}) async { - String playerName = searchBarController.text.trim(); - bool success = await db.playerDao.addPlayer(player: Player(name: playerName)); - if (!context.mounted) return; - if (success) { - loadPlayerList(); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - backgroundColor: CustomTheme.boxColor, - content: Center( - child: Text( - 'Successfully added player $playerName.', - style: const TextStyle(color: Colors.white), + /// Adds a new player to the database from the search bar input. + /// Shows a snackbar indicating success or failure. + /// [context] - BuildContext to show the snackbar. + void addNewPlayerFromSearch({required BuildContext context}) async { + String playerName = _searchBarController.text.trim(); + Player createdPlayer = Player(name: playerName); + bool success = await db.playerDao.addPlayer(player: createdPlayer); + if (!context.mounted) return; + if (success) { + selectedPlayers.add(createdPlayer); + allPlayers.add(createdPlayer); + setState(() { + _searchBarController.clear(); + suggestedPlayers = allPlayers.where((player) { + return !selectedPlayers.contains(player); + }).toList(); + }); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + backgroundColor: CustomTheme.boxColor, + content: Center( + child: Text( + 'Successfully added player $playerName.', + style: const TextStyle(color: Colors.white), + ), ), ), - ), - ); - searchBarController.clear(); - } else { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - backgroundColor: CustomTheme.boxColor, - content: Center( - child: Text( - 'Could not add player $playerName.', - style: const TextStyle(color: Colors.white), + ); + } else { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + backgroundColor: CustomTheme.boxColor, + content: Center( + child: Text( + 'Could not add player $playerName.', + style: const TextStyle(color: Colors.white), + ), ), ), - ), - ); + ); + } } } From cc04e0555768396560f28b20f108a6a0a5d29d02 Mon Sep 17 00:00:00 2001 From: mathiskirchner Date: Sat, 22 Nov 2025 22:49:28 +0100 Subject: [PATCH 2/4] Adjust bottom padding in GroupsView list based on media query padding --- lib/presentation/views/main_menu/groups_view.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/presentation/views/main_menu/groups_view.dart b/lib/presentation/views/main_menu/groups_view.dart index 4bf9cba..a23a615 100644 --- a/lib/presentation/views/main_menu/groups_view.dart +++ b/lib/presentation/views/main_menu/groups_view.dart @@ -93,7 +93,9 @@ class _GroupsViewState extends State { itemCount: groups.length + 1, itemBuilder: (BuildContext context, int index) { if (index == groups.length) { - return const SizedBox(height: 60); + return SizedBox( + height: MediaQuery.paddingOf(context).bottom - 20, + ); } return GroupTile(group: groups[index]); }, From 692b412fe2e3d7d727717aa36bd24ad29a5cd349 Mon Sep 17 00:00:00 2001 From: mathiskirchner Date: Sat, 22 Nov 2025 22:52:09 +0100 Subject: [PATCH 3/4] Fix black bars on the screens bottom and top by not wrapping scaffold in safearea, but scaffolds body children --- .../views/main_menu/create_group_view.dart | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/presentation/views/main_menu/create_group_view.dart b/lib/presentation/views/main_menu/create_group_view.dart index 75fdb83..b077bbc 100644 --- a/lib/presentation/views/main_menu/create_group_view.dart +++ b/lib/presentation/views/main_menu/create_group_view.dart @@ -66,19 +66,19 @@ class _CreateGroupViewState extends State { @override Widget build(BuildContext context) { - return SafeArea( - child: Scaffold( + return Scaffold( + backgroundColor: CustomTheme.backgroundColor, + appBar: AppBar( backgroundColor: CustomTheme.backgroundColor, - appBar: AppBar( - backgroundColor: CustomTheme.backgroundColor, - scrolledUnderElevation: 0, - title: const Text( - 'Create new group', - style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), - ), - centerTitle: true, + scrolledUnderElevation: 0, + title: const Text( + 'Create new group', + style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), ), - body: Column( + centerTitle: true, + ), + body: SafeArea( + child: Column( mainAxisAlignment: MainAxisAlignment.start, children: [ Container( From c170aa17752f808954b85d6270e33df46d91cad8 Mon Sep 17 00:00:00 2001 From: mathiskirchner Date: Sat, 22 Nov 2025 22:55:19 +0100 Subject: [PATCH 4/4] sort groups by creation date in GroupsView --- lib/presentation/views/main_menu/groups_view.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/presentation/views/main_menu/groups_view.dart b/lib/presentation/views/main_menu/groups_view.dart index a23a615..e9af8b9 100644 --- a/lib/presentation/views/main_menu/groups_view.dart +++ b/lib/presentation/views/main_menu/groups_view.dart @@ -69,9 +69,9 @@ class _GroupsViewState extends State { } final bool isLoading = snapshot.connectionState == ConnectionState.waiting; - final List groups = isLoading - ? skeletonData - : (snapshot.data ?? []); + final List groups = + isLoading ? skeletonData : (snapshot.data ?? []) + ..sort((a, b) => b.createdAt.compareTo(a.createdAt)); return Skeletonizer( effect: PulseEffect( from: Colors.grey[800]!,