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