Extracted code to method _playFinishAnimation()
This commit is contained in:
@@ -441,7 +441,7 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
||||
/// It starts with the given [roundNumber] and continues to open the next round
|
||||
/// until the user navigates back or the round number is invalid.
|
||||
void _openRoundView(BuildContext context, int roundNumber) async {
|
||||
final val = await Navigator.of(context, rootNavigator: true).push(
|
||||
final round = await Navigator.of(context, rootNavigator: true).push(
|
||||
CupertinoPageRoute(
|
||||
fullscreenDialog: true,
|
||||
builder: (context) => RoundView(
|
||||
@@ -450,7 +450,24 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
||||
),
|
||||
),
|
||||
);
|
||||
if (widget.gameSession.isGameFinished && mounted) {
|
||||
|
||||
if (widget.gameSession.isGameFinished && context.mounted) {
|
||||
_playFinishAnimation(context);
|
||||
}
|
||||
|
||||
// If the previous round was not the last one
|
||||
if (round != null && round >= 0) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
await Future.delayed(const Duration(milliseconds: 600));
|
||||
if (context.mounted) {
|
||||
_openRoundView(context, round);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Plays the confetti animation and shows a dialog with the winner's information.
|
||||
Future<void> _playFinishAnimation(BuildContext context) async {
|
||||
String winner = widget.gameSession.winner;
|
||||
int winnerIndex = widget.gameSession.players.indexOf(winner);
|
||||
int points = widget.gameSession.playerScores[winnerIndex];
|
||||
@@ -480,13 +497,4 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
||||
});
|
||||
}
|
||||
}
|
||||
if (val != null && val >= 0) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
await Future.delayed(const Duration(milliseconds: 600));
|
||||
if (context.mounted) {
|
||||
_openRoundView(context, val);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user