Instantly share code, notes, and snippets.

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

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