Instantly share code, notes, and snippets.

@MarcinusX MarcinusX/main.dart Secret
Created Jan 14, 2019

Embed
What would you like to do?
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