Fixed button state
This commit is contained in:
@@ -52,6 +52,9 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
/// the [ChooseRulesetView]
|
/// the [ChooseRulesetView]
|
||||||
int selectedRulesetIndex = -1;
|
int selectedRulesetIndex = -1;
|
||||||
|
|
||||||
|
/// The currently selected players
|
||||||
|
List<Player>? selectedPlayers;
|
||||||
|
|
||||||
/// List of available rulesets with their display names and descriptions
|
/// List of available rulesets with their display names and descriptions
|
||||||
/// as tuples of (Ruleset, String, String)
|
/// as tuples of (Ruleset, String, String)
|
||||||
List<(Ruleset, String, String)> rulesets = [
|
List<(Ruleset, String, String)> rulesets = [
|
||||||
@@ -213,7 +216,9 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
)
|
)
|
||||||
.toList(),
|
.toList(),
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
print(value);
|
setState(() {
|
||||||
|
selectedPlayers = value;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -222,21 +227,19 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
text: 'Create game',
|
text: 'Create game',
|
||||||
sizeRelativeToWidth: 0.95,
|
sizeRelativeToWidth: 0.95,
|
||||||
buttonType: ButtonType.primary,
|
buttonType: ButtonType.primary,
|
||||||
onPressed:
|
onPressed: _enableCreateGameButton()
|
||||||
(_gameNameController.text.isEmpty ||
|
? () async {
|
||||||
selectedGroup == null ||
|
|
||||||
selectedRuleset == null)
|
|
||||||
? null
|
|
||||||
: () async {
|
|
||||||
Game game = Game(
|
Game game = Game(
|
||||||
name: _gameNameController.text.trim(),
|
name: _gameNameController.text.trim(),
|
||||||
createdAt: DateTime.now(),
|
createdAt: DateTime.now(),
|
||||||
group: selectedGroup!,
|
group: selectedGroup!,
|
||||||
|
players: selectedPlayers,
|
||||||
);
|
);
|
||||||
// TODO: Replace with navigation to GameResultView()
|
// TODO: Replace with navigation to GameResultView()
|
||||||
print('Created game: $game');
|
print('Created game: $game');
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
},
|
}
|
||||||
|
: null,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
],
|
],
|
||||||
@@ -258,4 +261,13 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
return 'Least Points';
|
return 'Least Points';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Determines whether the "Create Game" button should be enabled based on
|
||||||
|
/// the current state of the input fields.
|
||||||
|
bool _enableCreateGameButton() {
|
||||||
|
return _gameNameController.text.isNotEmpty &&
|
||||||
|
(selectedGroup != null ||
|
||||||
|
(selectedPlayers != null && selectedPlayers!.isNotEmpty)) &&
|
||||||
|
selectedRuleset != null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user