mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 16:05:18 +00:00
Merge pull request #340 from tiaxter/feat-shuffle-button
feat: shuffle button in playlist and album section
This commit is contained in:
commit
166710f041
20
lib/components/shared/playlist_shuffle_button.dart
Normal file
20
lib/components/shared/playlist_shuffle_button.dart
Normal file
@ -0,0 +1,20 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:platform_ui/platform_ui.dart';
|
||||
|
||||
class PlaylistShuffleButton extends StatelessWidget {
|
||||
final onPressed;
|
||||
|
||||
const PlaylistShuffleButton({
|
||||
Key? key,
|
||||
this.onPressed,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PlatformIconButton(
|
||||
tooltip: "Shuffle",
|
||||
icon: const Icon(Icons.shuffle),
|
||||
onPressed: this.onPressed,
|
||||
);
|
||||
}
|
||||
}
|
@ -26,6 +26,7 @@ class TrackCollectionView<T> extends HookConsumerWidget {
|
||||
final void Function([Track? currentTrack]) onPlay;
|
||||
final void Function() onShare;
|
||||
final Widget? heartBtn;
|
||||
final Widget? shuffleButton;
|
||||
final AlbumSimple? album;
|
||||
|
||||
final bool showShare;
|
||||
@ -43,6 +44,7 @@ class TrackCollectionView<T> extends HookConsumerWidget {
|
||||
required this.onShare,
|
||||
required this.routePath,
|
||||
this.heartBtn,
|
||||
this.shuffleButton,
|
||||
this.album,
|
||||
this.description,
|
||||
this.showShare = true,
|
||||
@ -68,6 +70,7 @@ class TrackCollectionView<T> extends HookConsumerWidget {
|
||||
onPressed: onShare,
|
||||
),
|
||||
if (heartBtn != null) heartBtn!,
|
||||
if (shuffleButton != null) shuffleButton!,
|
||||
const SizedBox(width: 5),
|
||||
// play playlist
|
||||
PlatformIconButton(
|
||||
|
@ -14,6 +14,7 @@ import 'package:spotube/utils/type_conversion_utils.dart';
|
||||
import 'package:spotube/models/current_playlist.dart';
|
||||
import 'package:spotube/provider/playback_provider.dart';
|
||||
import 'package:spotube/provider/spotify_provider.dart';
|
||||
import 'package:spotube/components/shared/playlist_shuffle_button.dart';
|
||||
|
||||
class AlbumPage extends HookConsumerWidget {
|
||||
final AlbumSimple album;
|
||||
@ -112,6 +113,26 @@ class AlbumPage extends HookConsumerWidget {
|
||||
);
|
||||
},
|
||||
heartBtn: AlbumHeartButton(album: album),
|
||||
shuffleButton: PlaylistShuffleButton(onPressed: () {
|
||||
var albumTracks = tracksSnapshot.data!
|
||||
.map((track) =>
|
||||
TypeConversionUtils.simpleTrack_X_Track(track, album))
|
||||
.toList();
|
||||
// Shuffle the tracks (create a copy of playlist)
|
||||
var tracks = [...albumTracks];
|
||||
tracks.shuffle();
|
||||
|
||||
// If playback is playing a track then pause it
|
||||
if (playback.isPlaying) {
|
||||
playback.pause();
|
||||
}
|
||||
|
||||
// Play the shuffled playlist
|
||||
playPlaylist( playback,
|
||||
tracks,
|
||||
ref,
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import 'package:spotube/services/queries/queries.dart';
|
||||
|
||||
import 'package:spotube/utils/service_utils.dart';
|
||||
import 'package:spotube/utils/type_conversion_utils.dart';
|
||||
import 'package:spotube/components/shared/playlist_shuffle_button.dart';
|
||||
|
||||
class PlaylistView extends HookConsumerWidget {
|
||||
final logger = getLogger(PlaylistView);
|
||||
@ -126,6 +127,23 @@ class PlaylistView extends HookConsumerWidget {
|
||||
});
|
||||
},
|
||||
heartBtn: PlaylistHeartButton(playlist: playlist),
|
||||
shuffleButton: PlaylistShuffleButton(onPressed: () {
|
||||
// Shuffle the tracks (create a copy of playlist)
|
||||
var tracks = [...?tracksSnapshot.data];
|
||||
tracks.shuffle();
|
||||
|
||||
// If playback is playing a track then pause it
|
||||
if (playback.isPlaying) {
|
||||
playback.pause();
|
||||
}
|
||||
|
||||
// Play the shuffled playlist
|
||||
playPlaylist( playback,
|
||||
tracks,
|
||||
ref,
|
||||
currentTrack: null,
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user