-
-
Save MarcinusX/c89aa500ce687ae8b27f18c89038080d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class _MainPageState extends State<MainPage> with SingleTickerProviderStateMixin { | |
... | |
@override | |
void initState() { | |
super.initState(); | |
animationController = AnimationController(vsync: this, duration: Duration(milliseconds: 300)); | |
animationController.addStatusListener((status) { | |
if (status == AnimationStatus.completed && isPlaying) { | |
if (notes[currentNoteIndex].state != NoteState.tapped) { | |
//game over | |
setState(() { | |
isPlaying = false; | |
notes[currentNoteIndex].state = NoteState.missed; | |
}); | |
animationController.reverse().then((_) => _showFinishDialog()); //<--Show dialog when reverse animaiton finishes | |
} else if (currentNoteIndex == notes.length - 5) { | |
//song finished | |
_showFinishDialog(); //<--Show dialog when song is finished | |
} else { | |
setState(() => ++currentNoteIndex); | |
animationController.forward(from: 0); | |
} | |
} | |
}); | |
} | |
void _showFinishDialog() { | |
showDialog( //<--Show a dialog | |
context: context, | |
builder: (context) { | |
return AlertDialog( | |
title: Text("Score: $points"), //<--With number of points | |
actions: <Widget>[ | |
FlatButton( //<-- and restart button | |
onPressed: () => Navigator.of(context).pop(), | |
child: Text("RESTART"), | |
), | |
], | |
); | |
}, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment