implement optional match name with game name as default
Some checks failed
Pull Request Pipeline / test (pull_request) Successful in 2m23s
Pull Request Pipeline / lint (pull_request) Failing after 2m24s

This commit is contained in:
2026-01-01 19:13:50 +01:00
parent fc6c74b377
commit 5ee0d59377

View File

@@ -31,6 +31,8 @@ class _CreateMatchViewState extends State<CreateMatchView> {
/// Controller for the match name input field /// Controller for the match name input field
final TextEditingController _matchNameController = TextEditingController(); final TextEditingController _matchNameController = TextEditingController();
String hintText = "Match Name";
/// List of all groups from the database /// List of all groups from the database
List<Group> groupsList = []; List<Group> groupsList = [];
@@ -132,7 +134,7 @@ class _CreateMatchViewState extends State<CreateMatchView> {
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 5), margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 5),
child: TextInputField( child: TextInputField(
controller: _matchNameController, controller: _matchNameController,
hintText: 'Match name', hintText: hintText,
), ),
), ),
ChooseTile( ChooseTile(
@@ -151,11 +153,13 @@ class _CreateMatchViewState extends State<CreateMatchView> {
); );
setState(() { setState(() {
if (selectedGameIndex != -1) { if (selectedGameIndex != -1) {
hintText = games[selectedGameIndex].$1;
selectedRuleset = games[selectedGameIndex].$3; selectedRuleset = games[selectedGameIndex].$3;
selectedRulesetIndex = rulesets.indexWhere( selectedRulesetIndex = rulesets.indexWhere(
(r) => r.$1 == selectedRuleset, (r) => r.$1 == selectedRuleset,
); );
} else { } else {
hintText = "Match Name";
selectedRuleset = null; selectedRuleset = null;
} }
}); });
@@ -228,7 +232,9 @@ class _CreateMatchViewState extends State<CreateMatchView> {
onPressed: _enableCreateGameButton() onPressed: _enableCreateGameButton()
? () async { ? () async {
Match match = Match( Match match = Match(
name: _matchNameController.text.trim(), name: _matchNameController.text.isEmpty
? hintText.trim()
: _matchNameController.text.trim(),
createdAt: DateTime.now(), createdAt: DateTime.now(),
group: selectedGroup, group: selectedGroup,
players: selectedPlayers, players: selectedPlayers,
@@ -258,9 +264,8 @@ class _CreateMatchViewState extends State<CreateMatchView> {
/// Determines whether the "Create Game" button should be enabled based on /// Determines whether the "Create Game" button should be enabled based on
/// the current state of the input fields. /// the current state of the input fields.
bool _enableCreateGameButton() { bool _enableCreateGameButton() {
return _matchNameController.text.isNotEmpty && return selectedGroup != null ||
(selectedGroup != null || (selectedPlayers != null && selectedPlayers!.length > 1) &&
(selectedPlayers != null && selectedPlayers!.length > 1)) &&
selectedRuleset != null; selectedRuleset != null;
} }
} }