Skip to content

Instantly share code, notes, and snippets.

@MarcinusX
Created January 14, 2019 05:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarcinusX/c89aa500ce687ae8b27f18c89038080d to your computer and use it in GitHub Desktop.
Save MarcinusX/c89aa500ce687ae8b27f18c89038080d to your computer and use it in GitHub Desktop.
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