-
-
Save MarcinusX/c42aa8fc9a2522a98c2a32af30e1ea8e 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 { | |
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