diff --git a/lib/presentation/views/main_menu/match_view/create_match/choose_game_view.dart b/lib/presentation/views/main_menu/match_view/create_match/choose_game_view.dart index 8e6eceb..5ed9d95 100644 --- a/lib/presentation/views/main_menu/match_view/create_match/choose_game_view.dart +++ b/lib/presentation/views/main_menu/match_view/create_match/choose_game_view.dart @@ -48,42 +48,53 @@ class _ChooseGameViewState extends State { ), centerTitle: true, ), - body: Column( - children: [ - Padding( - padding: const EdgeInsets.symmetric(horizontal: 10), - child: CustomSearchBar( - controller: searchBarController, - hintText: AppLocalizations.of(context).game_name, + body: PopScope( + // This fixes that the Android Back Gesture didn't return the + // selectedGameIndex and therefore the selected Game wasn't saved + canPop: false, + onPopInvokedWithResult: (bool didPop, Object? result) { + if (didPop) { + return; + } + Navigator.of(context).pop(selectedGameIndex); + }, + child: Column( + children: [ + Padding( + padding: const EdgeInsets.symmetric(horizontal: 10), + child: CustomSearchBar( + controller: searchBarController, + hintText: AppLocalizations.of(context).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( + 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, context, ), - isHighlighted: selectedGameIndex == index, - onPressed: () async { - setState(() { - if (selectedGameIndex == index) { - selectedGameIndex = -1; - } else { - selectedGameIndex = index; - } - }); - }, - ); - }, + isHighlighted: selectedGameIndex == index, + onPressed: () async { + setState(() { + if (selectedGameIndex == index) { + selectedGameIndex = -1; + } else { + selectedGameIndex = index; + } + }); + }, + ); + }, + ), ), - ), - ], + ], + ), ), ); } diff --git a/lib/presentation/views/main_menu/match_view/create_match/choose_group_view.dart b/lib/presentation/views/main_menu/match_view/create_match/choose_group_view.dart index d05fff9..8a3f0f2 100644 --- a/lib/presentation/views/main_menu/match_view/create_match/choose_group_view.dart +++ b/lib/presentation/views/main_menu/match_view/create_match/choose_group_view.dart @@ -57,63 +57,80 @@ class _ChooseGroupViewState extends State { ), centerTitle: true, ), - body: Column( - children: [ - Padding( - padding: const EdgeInsets.symmetric(horizontal: 10), - child: CustomSearchBar( - controller: controller, - hintText: AppLocalizations.of(context).search_for_groups, - onChanged: (value) { - setState(() { - filterGroups(value); - }); - }, - ), - ), - Expanded( - child: Visibility( - visible: filteredGroups.isNotEmpty, - replacement: Visibility( - visible: widget.groups.isNotEmpty, - replacement: TopCenteredMessage( - icon: Icons.info, - title: AppLocalizations.of(context).info, - message: AppLocalizations.of(context).no_groups_created_yet, - ), - child: TopCenteredMessage( - icon: Icons.info, - title: AppLocalizations.of(context).info, - message: AppLocalizations.of( - context, - ).there_is_no_group_matching_your_search, - ), - ), - child: ListView.builder( - padding: const EdgeInsets.only(bottom: 85), - itemCount: filteredGroups.length, - itemBuilder: (BuildContext context, int index) { - return GestureDetector( - onTap: () { - setState(() { - if (selectedGroupId != filteredGroups[index].id) { - selectedGroupId = filteredGroups[index].id; - } else { - selectedGroupId = ''; - } - }); - }, - child: GroupTile( - group: filteredGroups[index], - isHighlighted: - selectedGroupId == filteredGroups[index].id, - ), - ); + body: PopScope( + // This fixes that the Android Back Gesture didn't return the + // selectedGroupId and therefore the selected Group wasn't saved + canPop: false, + onPopInvokedWithResult: (bool didPop, Object? result) { + if (didPop) { + return; + } + Navigator.of(context).pop( + selectedGroupId == '' + ? null + : widget.groups.firstWhere( + (group) => group.id == selectedGroupId, + ), + ); + }, + child: Column( + children: [ + Padding( + padding: const EdgeInsets.symmetric(horizontal: 10), + child: CustomSearchBar( + controller: controller, + hintText: AppLocalizations.of(context).search_for_groups, + onChanged: (value) { + setState(() { + filterGroups(value); + }); }, ), ), - ), - ], + Expanded( + child: Visibility( + visible: filteredGroups.isNotEmpty, + replacement: Visibility( + visible: widget.groups.isNotEmpty, + replacement: TopCenteredMessage( + icon: Icons.info, + title: AppLocalizations.of(context).info, + message: AppLocalizations.of(context).no_groups_created_yet, + ), + child: TopCenteredMessage( + icon: Icons.info, + title: AppLocalizations.of(context).info, + message: AppLocalizations.of( + context, + ).there_is_no_group_matching_your_search, + ), + ), + child: ListView.builder( + padding: const EdgeInsets.only(bottom: 85), + itemCount: filteredGroups.length, + itemBuilder: (BuildContext context, int index) { + return GestureDetector( + onTap: () { + setState(() { + if (selectedGroupId != filteredGroups[index].id) { + selectedGroupId = filteredGroups[index].id; + } else { + selectedGroupId = ''; + } + }); + }, + child: GroupTile( + group: filteredGroups[index], + isHighlighted: + selectedGroupId == filteredGroups[index].id, + ), + ); + }, + ), + ), + ), + ], + ), ), ); } diff --git a/lib/presentation/views/main_menu/match_view/create_match/choose_ruleset_view.dart b/lib/presentation/views/main_menu/match_view/create_match/choose_ruleset_view.dart index 9383be2..f47b535 100644 --- a/lib/presentation/views/main_menu/match_view/create_match/choose_ruleset_view.dart +++ b/lib/presentation/views/main_menu/match_view/create_match/choose_ruleset_view.dart @@ -53,28 +53,43 @@ class _ChooseRulesetViewState extends State { ), centerTitle: true, ), - body: ListView.builder( - padding: const EdgeInsets.only(bottom: 85), - itemCount: widget.rulesets.length, - itemBuilder: (BuildContext context, int index) { - return TitleDescriptionListTile( - onPressed: () async { - setState(() { - if (selectedRulesetIndex == index) { - selectedRulesetIndex = -1; - } else { - selectedRulesetIndex = index; - } - }); - }, - title: translateRulesetToString( + body: PopScope( + // This fixes that the Android Back Gesture didn't return the + // selectedRulesetIndex and therefore the selected Ruleset wasn't saved + canPop: false, + onPopInvokedWithResult: (bool didPop, Object? result) { + if (didPop) { + return; + } + Navigator.of(context).pop( + selectedRulesetIndex == -1 + ? null + : widget.rulesets[selectedRulesetIndex].$1, + ); + }, + child: ListView.builder( + padding: const EdgeInsets.only(bottom: 85), + itemCount: widget.rulesets.length, + itemBuilder: (BuildContext context, int index) { + return TitleDescriptionListTile( + onPressed: () async { + setState(() { + if (selectedRulesetIndex == index) { + selectedRulesetIndex = -1; + } else { + selectedRulesetIndex = index; + } + }); + }, + title: translateRulesetToString( widget.rulesets[index].$1, context, ), - description: widget.rulesets[index].$2, - isHighlighted: selectedRulesetIndex == index, - ); - }, + description: widget.rulesets[index].$2, + isHighlighted: selectedRulesetIndex == index, + ); + }, + ), ), ), );