✨ Playable playlist screen
This commit is contained in:
parent
70039a4901
commit
c0714ab3c8
@ -23,10 +23,13 @@ class LyricsScreen extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
bottomNavigationBar: const SizedBox(
|
bottomNavigationBar: const SizedBox(
|
||||||
height: 83,
|
height: 85,
|
||||||
child: Material(
|
child: Material(
|
||||||
elevation: 2,
|
elevation: 2,
|
||||||
child: BottomPlayer(usePop: true),
|
child: BottomPlayer(
|
||||||
|
key: Key('lyrics-page-bottom-player'),
|
||||||
|
usePop: true,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:gap/gap.dart';
|
import 'package:gap/gap.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:google_fonts/google_fonts.dart';
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:rhythm_box/providers/audio_player.dart';
|
||||||
|
import 'package:rhythm_box/providers/history.dart';
|
||||||
import 'package:rhythm_box/providers/spotify.dart';
|
import 'package:rhythm_box/providers/spotify.dart';
|
||||||
|
import 'package:rhythm_box/services/audio_player/audio_player.dart';
|
||||||
import 'package:rhythm_box/widgets/auto_cache_image.dart';
|
import 'package:rhythm_box/widgets/auto_cache_image.dart';
|
||||||
import 'package:rhythm_box/widgets/tracks/playlist_track_list.dart';
|
import 'package:rhythm_box/widgets/tracks/playlist_track_list.dart';
|
||||||
import 'package:spotify/spotify.dart';
|
import 'package:spotify/spotify.dart';
|
||||||
@ -24,8 +29,14 @@ class PlaylistViewScreen extends StatefulWidget {
|
|||||||
|
|
||||||
class _PlaylistViewScreenState extends State<PlaylistViewScreen> {
|
class _PlaylistViewScreenState extends State<PlaylistViewScreen> {
|
||||||
late final SpotifyProvider _spotify = Get.find();
|
late final SpotifyProvider _spotify = Get.find();
|
||||||
|
late final AudioPlayerProvider _playback = Get.find();
|
||||||
|
|
||||||
|
bool get _isCurrentPlaylist => _playlist != null
|
||||||
|
? _playback.state.value.containsCollection(_playlist!.id!)
|
||||||
|
: false;
|
||||||
|
|
||||||
bool _isLoading = true;
|
bool _isLoading = true;
|
||||||
|
bool _isUpdating = false;
|
||||||
|
|
||||||
Playlist? _playlist;
|
Playlist? _playlist;
|
||||||
|
|
||||||
@ -116,15 +127,73 @@ class _PlaylistViewScreenState extends State<PlaylistViewScreen> {
|
|||||||
Wrap(
|
Wrap(
|
||||||
spacing: 8,
|
spacing: 8,
|
||||||
children: [
|
children: [
|
||||||
ElevatedButton.icon(
|
Obx(
|
||||||
icon: const Icon(Icons.play_arrow_outlined),
|
() => ElevatedButton.icon(
|
||||||
label: const Text('Play'),
|
icon: (_isCurrentPlaylist &&
|
||||||
onPressed: () {},
|
_playback.isPlaying.value)
|
||||||
|
? const Icon(Icons.pause_outlined)
|
||||||
|
: const Icon(Icons.play_arrow),
|
||||||
|
label: const Text('Play'),
|
||||||
|
onPressed: _isUpdating
|
||||||
|
? null
|
||||||
|
: () async {
|
||||||
|
if (_isCurrentPlaylist &&
|
||||||
|
_playback.isPlaying.value) {
|
||||||
|
audioPlayer.pause();
|
||||||
|
return;
|
||||||
|
} else if (_isCurrentPlaylist &&
|
||||||
|
!_playback.isPlaying.value) {
|
||||||
|
audioPlayer.resume();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setState(() => _isUpdating = true);
|
||||||
|
|
||||||
|
final tracks = (await _spotify
|
||||||
|
.api.playlists
|
||||||
|
.getTracksByPlaylistId(
|
||||||
|
widget.playlistId)
|
||||||
|
.all())
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
await _playback.load(tracks,
|
||||||
|
autoPlay: true);
|
||||||
|
_playback.addCollection(_playlist!.id!);
|
||||||
|
Get.find<PlaybackHistoryProvider>()
|
||||||
|
.addPlaylists([_playlist!]);
|
||||||
|
|
||||||
|
setState(() => _isUpdating = false);
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
TextButton.icon(
|
TextButton.icon(
|
||||||
icon: const Icon(Icons.shuffle),
|
icon: const Icon(Icons.shuffle),
|
||||||
label: const Text('Shuffle'),
|
label: const Text('Shuffle'),
|
||||||
onPressed: () {},
|
onPressed: _isUpdating
|
||||||
|
? null
|
||||||
|
: () async {
|
||||||
|
setState(() => _isUpdating = true);
|
||||||
|
|
||||||
|
audioPlayer.setShuffle(true);
|
||||||
|
|
||||||
|
final tracks = (await _spotify.api.playlists
|
||||||
|
.getTracksByPlaylistId(
|
||||||
|
widget.playlistId)
|
||||||
|
.all())
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
await _playback.load(
|
||||||
|
tracks,
|
||||||
|
autoPlay: true,
|
||||||
|
initialIndex:
|
||||||
|
Random().nextInt(tracks.length),
|
||||||
|
);
|
||||||
|
_playback.addCollection(_playlist!.id!);
|
||||||
|
Get.find<PlaybackHistoryProvider>()
|
||||||
|
.addPlaylists([_playlist!]);
|
||||||
|
|
||||||
|
setState(() => _isUpdating = false);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
).paddingSymmetric(horizontal: 24),
|
).paddingSymmetric(horizontal: 24),
|
||||||
|
@ -36,7 +36,7 @@ class _NavShellState extends State<NavShell> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
const BottomPlayer(),
|
const BottomPlayer(key: Key('app-wide-bottom-player')),
|
||||||
const Divider(height: 0.3, thickness: 0.3),
|
const Divider(height: 0.3, thickness: 0.3),
|
||||||
BottomNavigationBar(
|
BottomNavigationBar(
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
|
@ -141,7 +141,7 @@ class _SyncedLyricsState extends State<SyncedLyrics> {
|
|||||||
),
|
),
|
||||||
).animate(target: isActive ? 1 : 0).scale(
|
).animate(target: isActive ? 1 : 0).scale(
|
||||||
duration: 300.ms,
|
duration: 300.ms,
|
||||||
begin: const Offset(1, 1),
|
begin: const Offset(0.9, 0.9),
|
||||||
end: const Offset(1.3, 1.3),
|
end: const Offset(1.3, 1.3),
|
||||||
);
|
);
|
||||||
}).paddingSymmetric(horizontal: 12),
|
}).paddingSymmetric(horizontal: 12),
|
||||||
|
@ -70,11 +70,13 @@ class _PlaylistTrackListState extends State<PlaylistTrackList> {
|
|||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if (item == null) return;
|
if (item == null) return;
|
||||||
Get.find<AudioPlayerProvider>().load(
|
Get.find<AudioPlayerProvider>()
|
||||||
_tracks!,
|
..load(
|
||||||
initialIndex: idx,
|
_tracks!,
|
||||||
autoPlay: true,
|
initialIndex: idx,
|
||||||
);
|
autoPlay: true,
|
||||||
|
)
|
||||||
|
..addCollection(widget.playlistId);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user