From 10aad4712438188a0d7bb798df2db8b05bf49446 Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Sat, 6 Dec 2025 17:13:33 +0100 Subject: [PATCH] Updated choosing mechanism --- .../create_game/choose_game_view.dart | 66 +++++++++++-------- .../create_game/choose_group_view.dart | 21 ++++-- .../create_game/choose_ruleset_view.dart | 20 ++++-- 3 files changed, 67 insertions(+), 40 deletions(-) diff --git a/lib/presentation/views/main_menu/create_game/choose_game_view.dart b/lib/presentation/views/main_menu/create_game/choose_game_view.dart index 8d8279e..5b2463b 100644 --- a/lib/presentation/views/main_menu/create_game/choose_game_view.dart +++ b/lib/presentation/views/main_menu/create_game/choose_game_view.dart @@ -35,42 +35,50 @@ class _ChooseGameViewState extends State { appBar: AppBar( backgroundColor: CustomTheme.backgroundColor, scrolledUnderElevation: 0, + leading: IconButton( + icon: const Icon(Icons.arrow_back_ios), + onPressed: () { + Navigator.of( + context, + ).pop(selectedGameIndex == -1 ? null : selectedGameIndex); + }, + ), title: const Text( 'Choose Game', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), ), centerTitle: true, ), - body: Column( - children: [ - CustomSearchBar( - controller: searchBarController, - hintText: 'Game Name', - ), - const SizedBox(height: 5), - Expanded( - child: ListView.builder( - itemCount: widget.games.length, - itemBuilder: (BuildContext context, int index) { - return TitleDescriptionListTile( - title: widget.games[index].$1, - description: widget.games[index].$2, - badgeText: translateRulesetToString(widget.games[index].$3), - isHighlighted: selectedGameIndex == index, - onPressed: () async { - setState(() { - selectedGameIndex = index; - }); - Future.delayed(const Duration(milliseconds: 500), () { - if (!context.mounted) return; - Navigator.of(context).pop(selectedGameIndex); - }); - }, - ); - }, + body: Container( + decoration: CustomTheme.standardBoxDecoration, + padding: const EdgeInsets.all(10), + child: Column( + children: [ + CustomSearchBar( + controller: searchBarController, + hintText: 'Game Name', ), - ), - ], + const SizedBox(height: 5), + Expanded( + child: ListView.builder( + itemCount: widget.games.length, + itemBuilder: (BuildContext context, int index) { + return TitleDescriptionListTile( + title: widget.games[index].$1, + description: widget.games[index].$2, + badgeText: translateRulesetToString(widget.games[index].$3), + isHighlighted: selectedGameIndex == index, + onPressed: () async { + setState(() { + selectedGameIndex = index; + }); + }, + ); + }, + ), + ), + ], + ), ), ); } diff --git a/lib/presentation/views/main_menu/create_game/choose_group_view.dart b/lib/presentation/views/main_menu/create_game/choose_group_view.dart index c98ce6d..de512bf 100644 --- a/lib/presentation/views/main_menu/create_game/choose_group_view.dart +++ b/lib/presentation/views/main_menu/create_game/choose_group_view.dart @@ -33,6 +33,16 @@ class _ChooseGroupViewState extends State { appBar: AppBar( backgroundColor: CustomTheme.backgroundColor, scrolledUnderElevation: 0, + leading: IconButton( + icon: const Icon(Icons.arrow_back_ios), + onPressed: () { + Navigator.of(context).pop( + selectedGroupIndex == -1 + ? null + : widget.groups[selectedGroupIndex], + ); + }, + ), title: const Text( 'Choose Group', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), @@ -46,12 +56,11 @@ class _ChooseGroupViewState extends State { return GestureDetector( onTap: () { setState(() { - selectedGroupIndex = index; - }); - - Future.delayed(const Duration(milliseconds: 500), () { - if (!context.mounted) return; - Navigator.of(context).pop(widget.groups[index]); + if (selectedGroupIndex == index) { + selectedGroupIndex = -1; + } else { + selectedGroupIndex = index; + } }); }, child: GroupTile( diff --git a/lib/presentation/views/main_menu/create_game/choose_ruleset_view.dart b/lib/presentation/views/main_menu/create_game/choose_ruleset_view.dart index 2e45a7c..13a9647 100644 --- a/lib/presentation/views/main_menu/create_game/choose_ruleset_view.dart +++ b/lib/presentation/views/main_menu/create_game/choose_ruleset_view.dart @@ -36,6 +36,16 @@ class _ChooseRulesetViewState extends State { appBar: AppBar( backgroundColor: CustomTheme.backgroundColor, scrolledUnderElevation: 0, + leading: IconButton( + icon: const Icon(Icons.arrow_back_ios), + onPressed: () { + Navigator.of(context).pop( + selectedRulesetIndex == -1 + ? null + : widget.rulesets[selectedRulesetIndex].$1, + ); + }, + ), title: const Text( 'Choose Ruleset', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), @@ -49,11 +59,11 @@ class _ChooseRulesetViewState extends State { return TitleDescriptionListTile( onPressed: () async { setState(() { - selectedRulesetIndex = index; - }); - Future.delayed(const Duration(milliseconds: 500), () { - if (!context.mounted) return; - Navigator.of(context).pop(widget.rulesets[index].$1); + if (selectedRulesetIndex == index) { + selectedRulesetIndex = -1; + } else { + selectedRulesetIndex = index; + } }); }, title: widget.rulesets[index].$2,