diff --git a/lib/presentation/views/main_menu/create_game/create_game_view.dart b/lib/presentation/views/main_menu/create_game/create_game_view.dart index 9b9b4d7..485118b 100644 --- a/lib/presentation/views/main_menu/create_game/create_game_view.dart +++ b/lib/presentation/views/main_menu/create_game/create_game_view.dart @@ -10,6 +10,7 @@ import 'package:game_tracker/presentation/views/main_menu/create_game/choose_rul import 'package:game_tracker/presentation/widgets/buttons/custom_width_button.dart'; import 'package:game_tracker/presentation/widgets/player_selection.dart'; import 'package:game_tracker/presentation/widgets/text_input/text_input_field.dart'; +import 'package:game_tracker/presentation/widgets/tiles/choose_tile.dart'; import 'package:provider/provider.dart'; class CreateGameView extends StatefulWidget { @@ -121,8 +122,12 @@ class _CreateGameViewState extends State { }, ), ), - GestureDetector( - onTap: () async { + ChooseTile( + title: 'Ruleset', + trailingText: selectedRuleset == null + ? 'None' + : translateRulesetToString(selectedRuleset!), + onPressed: () async { selectedRuleset = await Navigator.of(context).push( MaterialPageRoute( builder: (context) => ChooseRulesetView( @@ -136,36 +141,13 @@ class _CreateGameViewState extends State { ); setState(() {}); }, - child: Container( - margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 5), - padding: const EdgeInsets.symmetric( - vertical: 10, - horizontal: 15, - ), - decoration: CustomTheme.standardBoxDecoration, - child: Row( - children: [ - const Text( - 'Ruleset', - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold, - ), - ), - const Spacer(), - Text( - selectedRuleset == null - ? 'None' - : translateRulesetToString(selectedRuleset!), - ), - const SizedBox(width: 10), - const Icon(Icons.arrow_forward_ios, size: 16), - ], - ), - ), ), - GestureDetector( - onTap: () async { + ChooseTile( + title: 'Group', + trailingText: selectedGroup == null + ? 'None' + : selectedGroup!.name, + onPressed: () async { selectedGroup = await Navigator.of(context).push( MaterialPageRoute( builder: (context) => ChooseGroupView( @@ -179,29 +161,6 @@ class _CreateGameViewState extends State { ); setState(() {}); }, - child: Container( - margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 5), - padding: const EdgeInsets.symmetric( - vertical: 10, - horizontal: 15, - ), - decoration: CustomTheme.standardBoxDecoration, - child: Row( - children: [ - const Text( - 'Group', - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold, - ), - ), - const Spacer(), - Text(selectedGroup == null ? 'None' : selectedGroup!.name), - const SizedBox(width: 10), - const Icon(Icons.arrow_forward_ios, size: 16), - ], - ), - ), ), Expanded( child: PlayerSelection( diff --git a/lib/presentation/widgets/tiles/choose_tile.dart b/lib/presentation/widgets/tiles/choose_tile.dart new file mode 100644 index 0000000..10a695d --- /dev/null +++ b/lib/presentation/widgets/tiles/choose_tile.dart @@ -0,0 +1,43 @@ +import 'package:flutter/material.dart'; +import 'package:game_tracker/core/custom_theme.dart'; + +class ChooseTile extends StatefulWidget { + final String title; + final VoidCallback? onPressed; + final String? trailingText; + const ChooseTile({ + super.key, + required this.title, + this.trailingText, + this.onPressed, + }); + + @override + State createState() => _ChooseTileState(); +} + +class _ChooseTileState extends State { + @override + Widget build(BuildContext context) { + return GestureDetector( + onTap: widget.onPressed, + child: Container( + margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 5), + padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 15), + decoration: CustomTheme.standardBoxDecoration, + child: Row( + children: [ + Text( + widget.title, + style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold), + ), + const Spacer(), + if (widget.trailingText != null) Text(widget.trailingText!), + const SizedBox(width: 10), + const Icon(Icons.arrow_forward_ios, size: 16), + ], + ), + ), + ); + } +}