mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-12-06 07:29:42 +00:00
Fix state getting reassigned incorrectly and check on wrong index
This commit is contained in:
parent
a37fc4546b
commit
686638a918
@ -230,21 +230,10 @@ class AudioPlayerNotifier extends Notifier<AudioPlayerState> {
|
|||||||
.filter(tracks)
|
.filter(tracks)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
final remainingTracks = state.tracks.where(
|
|
||||||
(track) =>
|
|
||||||
allowDuplicates ||
|
|
||||||
!addableTracks.any((element) => _compareTracks(element, track))
|
|
||||||
)
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
state = state.copyWith(
|
|
||||||
tracks: [...addableTracks, ...remainingTracks],
|
|
||||||
);
|
|
||||||
|
|
||||||
for (int i = 0; i < addableTracks.length; i++) {
|
for (int i = 0; i < addableTracks.length; i++) {
|
||||||
final track = addableTracks.elementAt(i);
|
final track = addableTracks.elementAt(i);
|
||||||
|
|
||||||
final (currentIndex, _) = remainingTracks
|
final (currentTrackIndex, _) = state.tracks
|
||||||
.indexed
|
.indexed
|
||||||
.cast<(int, SpotubeTrackObject?)>()
|
.cast<(int, SpotubeTrackObject?)>()
|
||||||
.firstWhere(
|
.firstWhere(
|
||||||
@ -257,13 +246,13 @@ class AudioPlayerNotifier extends Notifier<AudioPlayerState> {
|
|||||||
|
|
||||||
final newIndex = max(state.currentIndex, 0) + i + 1;
|
final newIndex = max(state.currentIndex, 0) + i + 1;
|
||||||
|
|
||||||
if (allowDuplicates || newIndex < 0) {
|
if (allowDuplicates || currentTrackIndex < 0) {
|
||||||
await audioPlayer.addTrackAt(
|
await audioPlayer.addTrackAt(
|
||||||
SpotubeMedia(track),
|
SpotubeMedia(track),
|
||||||
newIndex
|
newIndex
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
await audioPlayer.moveTrack(currentIndex, newIndex);
|
await audioPlayer.moveTrack(currentTrackIndex, newIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user