Improved Button behaviour with input checker
This commit is contained in:
@@ -22,12 +22,8 @@ class _RoundViewState extends State<RoundView> {
|
|||||||
/// Index of the player who said CABO.
|
/// Index of the player who said CABO.
|
||||||
int _caboPlayerIndex = 0;
|
int _caboPlayerIndex = 0;
|
||||||
|
|
||||||
int? _kamikazePlayerIndex; // null = kein Kamikaze, sonst Spielerindex
|
/// Index of the player who has Kamikaze. Default is null (no kamikaze player).
|
||||||
|
int? _kamikazePlayerIndex;
|
||||||
/// List of booleans that represent whether the kamikaze checkbox is checked
|
|
||||||
/// for a player on that index.
|
|
||||||
late final List<bool> _isKamikazeChecked =
|
|
||||||
List.filled(widget.gameSession.players.length, false);
|
|
||||||
|
|
||||||
/// List of text controllers for the point text fields.
|
/// List of text controllers for the point text fields.
|
||||||
late final List<TextEditingController> _pointControllers = List.generate(
|
late final List<TextEditingController> _pointControllers = List.generate(
|
||||||
@@ -233,26 +229,26 @@ class _RoundViewState extends State<RoundView> {
|
|||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
children: [
|
children: [
|
||||||
CupertinoButton(
|
CupertinoButton(
|
||||||
|
onPressed: _areRoundInputsValid()
|
||||||
|
? () => {_finishRound(), Navigator.pop(context)}
|
||||||
|
: null,
|
||||||
child: const Text('Fertig'),
|
child: const Text('Fertig'),
|
||||||
onPressed: () => Navigator.pop(context),
|
|
||||||
),
|
),
|
||||||
CupertinoButton(
|
CupertinoButton(
|
||||||
child: const Text('Nächste Runde'),
|
onPressed: _areRoundInputsValid()
|
||||||
onPressed: () => {
|
? () => {
|
||||||
print('===================================='),
|
_finishRound(),
|
||||||
print('Runde ${widget.roundNumber} beendet'),
|
Navigator.pushReplacement(context,
|
||||||
if (widget.roundNumber >=
|
CupertinoPageRoute(
|
||||||
widget.gameSession.playerScores[0].length)
|
builder: (context) {
|
||||||
{gameSession.expandPlayerScoreLists()},
|
return RoundView(
|
||||||
_checkForWinner(),
|
gameSession: widget.gameSession,
|
||||||
widget.gameSession.sumPoints(),
|
roundNumber:
|
||||||
Navigator.pushReplacement(context,
|
widget.roundNumber + 1);
|
||||||
CupertinoPageRoute(builder: (context) {
|
})),
|
||||||
return RoundView(
|
}
|
||||||
gameSession: widget.gameSession,
|
: null,
|
||||||
roundNumber: widget.roundNumber + 1);
|
child: const Text('Nächste Runde')),
|
||||||
})),
|
|
||||||
}),
|
|
||||||
],
|
],
|
||||||
)),
|
)),
|
||||||
),
|
),
|
||||||
@@ -261,6 +257,29 @@ class _RoundViewState extends State<RoundView> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool _areRoundInputsValid() {
|
||||||
|
if (_kamikazePlayerIndex == null) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
for (TextEditingController c in _pointControllers) {
|
||||||
|
if (c.text.isEmpty) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _finishRound() {
|
||||||
|
print('====================================');
|
||||||
|
print('Runde ${widget.roundNumber} beendet');
|
||||||
|
if (widget.roundNumber >= widget.gameSession.playerScores[0].length) {
|
||||||
|
gameSession.expandPlayerScoreLists();
|
||||||
|
}
|
||||||
|
_checkForWinner();
|
||||||
|
widget.gameSession.sumPoints();
|
||||||
|
}
|
||||||
|
|
||||||
/// Checks the scores of the current round and assigns points to the players.
|
/// Checks the scores of the current round and assigns points to the players.
|
||||||
/// There are three possible outcomes of a round:
|
/// There are three possible outcomes of a round:
|
||||||
///
|
///
|
||||||
|
|||||||
Reference in New Issue
Block a user