implement optional match name with game name as default
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user