Skip to content

Instantly share code, notes, and snippets.

@MarcinusX
Created January 13, 2019 07:03
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/c42aa8fc9a2522a98c2a32af30e1ea8e to your computer and use it in GitHub Desktop.
Save MarcinusX/c42aa8fc9a2522a98c2a32af30e1ea8e to your computer and use it in GitHub Desktop.
class _MainPageState extends State<MainPage> with SingleTickerProviderStateMixin {
List<Note> notes = initNotes();
int currentNoteIndex = 0;
AnimationController animationController;
@override
void initState() {
super.initState();
animationController =
AnimationController(vsync: this, duration: Duration(milliseconds: 300)); //<--- Init the AnimationController
animationController.addStatusListener((status) {
if (status == AnimationStatus.completed) { //<--- Whenever animation finishes
if (currentNoteIndex == notes.length - 4) {
//song finished
} else { //<--- If the song didn't end
setState(() => ++currentNoteIndex); //<--- Increase currentNoteIndex
animationController.forward(from: 0); //<--- And start over the animation
}
}
});
animationController.forward(); //<--- start the animation for the first time
}
@override
void dispose() {
animationController.dispose(); //<--- remember to dispose the controller
super.dispose();
}
_drawLine(int lineNumber) {
return Expanded(
child: Line(
lineNumber: lineNumber,
currentNotes: notes.sublist(currentNoteIndex, currentNoteIndex + 4), //<--- use currentNoteIndex
),
);
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment