mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 16:05:18 +00:00
fix: playbutton card play state not changing
refactor(player_controls): move stop playback button to queue sheet
This commit is contained in:
parent
b8f3493138
commit
ee46d0970b
@ -24,7 +24,8 @@ class AlbumCard extends HookConsumerWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, ref) {
|
Widget build(BuildContext context, ref) {
|
||||||
final playlist = ref.watch(PlaylistQueueNotifier.provider);
|
final playlist = ref.watch(PlaylistQueueNotifier.provider);
|
||||||
final playing = useStream(PlaylistQueueNotifier.playing).data ?? false;
|
final playing = useStream(PlaylistQueueNotifier.playing).data ??
|
||||||
|
PlaylistQueueNotifier.isPlaying;
|
||||||
final playlistNotifier = ref.watch(PlaylistQueueNotifier.notifier);
|
final playlistNotifier = ref.watch(PlaylistQueueNotifier.notifier);
|
||||||
final queryBowl = QueryBowl.of(context);
|
final queryBowl = QueryBowl.of(context);
|
||||||
final query = queryBowl.getQuery<List<TrackSimple>, SpotifyApi>(
|
final query = queryBowl.getQuery<List<TrackSimple>, SpotifyApi>(
|
||||||
@ -33,6 +34,9 @@ class AlbumCard extends HookConsumerWidget {
|
|||||||
bool isPlaylistPlaying = playlistNotifier.isPlayingPlaylist(tracks.value);
|
bool isPlaylistPlaying = playlistNotifier.isPlayingPlaylist(tracks.value);
|
||||||
final int marginH =
|
final int marginH =
|
||||||
useBreakpointValue(sm: 10, md: 15, lg: 20, xl: 20, xxl: 20);
|
useBreakpointValue(sm: 10, md: 15, lg: 20, xl: 20, xxl: 20);
|
||||||
|
|
||||||
|
final updating = useState(false);
|
||||||
|
|
||||||
return PlaybuttonCard(
|
return PlaybuttonCard(
|
||||||
imageUrl: TypeConversionUtils.image_X_UrlString(
|
imageUrl: TypeConversionUtils.image_X_UrlString(
|
||||||
album.images,
|
album.images,
|
||||||
@ -49,6 +53,8 @@ class AlbumCard extends HookConsumerWidget {
|
|||||||
ServiceUtils.navigate(context, "/album/${album.id}", extra: album);
|
ServiceUtils.navigate(context, "/album/${album.id}", extra: album);
|
||||||
},
|
},
|
||||||
onPlaybuttonPressed: () async {
|
onPlaybuttonPressed: () async {
|
||||||
|
updating.value = true;
|
||||||
|
try {
|
||||||
if (isPlaylistPlaying && playing) {
|
if (isPlaylistPlaying && playing) {
|
||||||
return playlistNotifier.pause();
|
return playlistNotifier.pause();
|
||||||
} else if (isPlaylistPlaying && !playing) {
|
} else if (isPlaylistPlaying && !playing) {
|
||||||
@ -56,16 +62,21 @@ class AlbumCard extends HookConsumerWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await playlistNotifier.loadAndPlay(album.tracks
|
await playlistNotifier.loadAndPlay(album.tracks
|
||||||
?.map(
|
?.map((e) =>
|
||||||
(e) => TypeConversionUtils.simpleTrack_X_Track(e, album))
|
TypeConversionUtils.simpleTrack_X_Track(e, album))
|
||||||
.toList() ??
|
.toList() ??
|
||||||
[]);
|
[]);
|
||||||
|
} finally {
|
||||||
|
updating.value = false;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onAddToQueuePressed: () async {
|
onAddToQueuePressed: () async {
|
||||||
if (isPlaylistPlaying) {
|
if (isPlaylistPlaying) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updating.value = true;
|
||||||
|
try {
|
||||||
final fetchedTracks =
|
final fetchedTracks =
|
||||||
await queryBowl.fetchQuery<List<TrackSimple>, SpotifyApi>(
|
await queryBowl.fetchQuery<List<TrackSimple>, SpotifyApi>(
|
||||||
Queries.album.tracksOf(album.id!),
|
Queries.album.tracksOf(album.id!),
|
||||||
@ -86,6 +97,9 @@ class AlbumCard extends HookConsumerWidget {
|
|||||||
content: Text("Added ${album.tracks?.length} tracks to queue"),
|
content: Text("Added ${album.tracks?.length} tracks to queue"),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
} finally {
|
||||||
|
updating.value = false;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,8 @@ class PlayerControls extends HookConsumerWidget {
|
|||||||
[]);
|
[]);
|
||||||
final playlist = ref.watch(PlaylistQueueNotifier.provider);
|
final playlist = ref.watch(PlaylistQueueNotifier.provider);
|
||||||
final playlistNotifier = ref.watch(PlaylistQueueNotifier.notifier);
|
final playlistNotifier = ref.watch(PlaylistQueueNotifier.notifier);
|
||||||
final playing = useStream(PlaylistQueueNotifier.playing).data ?? false;
|
final playing = useStream(PlaylistQueueNotifier.playing).data ??
|
||||||
|
PlaylistQueueNotifier.isPlaying;
|
||||||
|
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
behavior: HitTestBehavior.translucent,
|
behavior: HitTestBehavior.translucent,
|
||||||
@ -89,6 +90,7 @@ class PlayerControls extends HookConsumerWidget {
|
|||||||
return null;
|
return null;
|
||||||
}, [progressStatic]);
|
}, [progressStatic]);
|
||||||
|
|
||||||
|
// this is a hack to fix duration not being updated
|
||||||
useEffect(() {
|
useEffect(() {
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||||
if (positionSnapshot.hasData &&
|
if (positionSnapshot.hasData &&
|
||||||
@ -200,14 +202,6 @@ class PlayerControls extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
onPressed: playlistNotifier.next,
|
onPressed: playlistNotifier.next,
|
||||||
),
|
),
|
||||||
PlatformIconButton(
|
|
||||||
tooltip: "Stop playback",
|
|
||||||
icon: Icon(
|
|
||||||
SpotubeIcons.stop,
|
|
||||||
color: iconColor,
|
|
||||||
),
|
|
||||||
onPressed: playlist != null ? playlistNotifier.stop : null,
|
|
||||||
),
|
|
||||||
PlatformIconButton(
|
PlatformIconButton(
|
||||||
tooltip: playlist?.isLooping != true
|
tooltip: playlist?.isLooping != true
|
||||||
? "Loop Track"
|
? "Loop Track"
|
||||||
|
@ -27,7 +27,8 @@ class PlayerOverlay extends HookConsumerWidget {
|
|||||||
PlaylistQueueNotifier.provider.select((s) => s != null),
|
PlaylistQueueNotifier.provider.select((s) => s != null),
|
||||||
);
|
);
|
||||||
final playlistNotifier = ref.watch(PlaylistQueueNotifier.notifier);
|
final playlistNotifier = ref.watch(PlaylistQueueNotifier.notifier);
|
||||||
final playing = useStream(PlaylistQueueNotifier.playing).data ?? false;
|
final playing = useStream(PlaylistQueueNotifier.playing).data ??
|
||||||
|
PlaylistQueueNotifier.isPlaying;
|
||||||
|
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onVerticalDragEnd: (details) {
|
onVerticalDragEnd: (details) {
|
||||||
|
@ -5,6 +5,7 @@ import 'package:flutter_hooks/flutter_hooks.dart';
|
|||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:platform_ui/platform_ui.dart';
|
import 'package:platform_ui/platform_ui.dart';
|
||||||
import 'package:scroll_to_index/scroll_to_index.dart';
|
import 'package:scroll_to_index/scroll_to_index.dart';
|
||||||
|
import 'package:spotube/collections/spotube_icons.dart';
|
||||||
import 'package:spotube/components/shared/fallbacks/not_found.dart';
|
import 'package:spotube/components/shared/fallbacks/not_found.dart';
|
||||||
import 'package:spotube/components/shared/track_table/track_tile.dart';
|
import 'package:spotube/components/shared/track_table/track_tile.dart';
|
||||||
import 'package:spotube/hooks/use_auto_scroll_controller.dart';
|
import 'package:spotube/hooks/use_auto_scroll_controller.dart';
|
||||||
@ -76,7 +77,33 @@ class PlayerQueue extends HookConsumerWidget {
|
|||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
PlatformText.subheading("Queue"),
|
PlatformAppBar(
|
||||||
|
title:
|
||||||
|
PlatformText.subheading("${tracks.length} tracks in Queue"),
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
|
automaticallyImplyLeading: false,
|
||||||
|
actions: [
|
||||||
|
PlatformFilledButton(
|
||||||
|
style: ButtonStyle(
|
||||||
|
backgroundColor: MaterialStatePropertyAll(
|
||||||
|
PlatformTheme.of(context)
|
||||||
|
.scaffoldBackgroundColor
|
||||||
|
?.withOpacity(0.5)),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: const [
|
||||||
|
Icon(SpotubeIcons.playlistRemove),
|
||||||
|
SizedBox(width: 5),
|
||||||
|
PlatformText("Clear All"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
playlistNotifier.stop();
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
Flexible(
|
Flexible(
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
|
@ -24,7 +24,8 @@ class PlaylistCard extends HookConsumerWidget {
|
|||||||
Widget build(BuildContext context, ref) {
|
Widget build(BuildContext context, ref) {
|
||||||
final playlistQueue = ref.watch(PlaylistQueueNotifier.provider);
|
final playlistQueue = ref.watch(PlaylistQueueNotifier.provider);
|
||||||
final playlistNotifier = ref.watch(PlaylistQueueNotifier.notifier);
|
final playlistNotifier = ref.watch(PlaylistQueueNotifier.notifier);
|
||||||
final playing = useStream(PlaylistQueueNotifier.playing).data ?? false;
|
final playing = useStream(PlaylistQueueNotifier.playing).data ??
|
||||||
|
PlaylistQueueNotifier.isPlaying;
|
||||||
final queryBowl = QueryBowl.of(context);
|
final queryBowl = QueryBowl.of(context);
|
||||||
final query = queryBowl.getQuery<List<Track>, SpotifyApi>(
|
final query = queryBowl.getQuery<List<Track>, SpotifyApi>(
|
||||||
Queries.playlist.tracksOf(playlist.id!).queryKey,
|
Queries.playlist.tracksOf(playlist.id!).queryKey,
|
||||||
@ -34,6 +35,9 @@ class PlaylistCard extends HookConsumerWidget {
|
|||||||
|
|
||||||
final int marginH =
|
final int marginH =
|
||||||
useBreakpointValue(sm: 10, md: 15, lg: 20, xl: 20, xxl: 20);
|
useBreakpointValue(sm: 10, md: 15, lg: 20, xl: 20, xxl: 20);
|
||||||
|
|
||||||
|
final updating = useState(false);
|
||||||
|
|
||||||
return PlaybuttonCard(
|
return PlaybuttonCard(
|
||||||
viewType: viewType,
|
viewType: viewType,
|
||||||
margin: EdgeInsets.symmetric(horizontal: marginH.toDouble()),
|
margin: EdgeInsets.symmetric(horizontal: marginH.toDouble()),
|
||||||
@ -43,7 +47,8 @@ class PlaylistCard extends HookConsumerWidget {
|
|||||||
placeholder: ImagePlaceholder.collection,
|
placeholder: ImagePlaceholder.collection,
|
||||||
),
|
),
|
||||||
isPlaying: isPlaylistPlaying && playing,
|
isPlaying: isPlaylistPlaying && playing,
|
||||||
isLoading: isPlaylistPlaying && playlistQueue?.isLoading == true,
|
isLoading: (isPlaylistPlaying && playlistQueue?.isLoading == true) ||
|
||||||
|
updating.value,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
ServiceUtils.navigate(
|
ServiceUtils.navigate(
|
||||||
context,
|
context,
|
||||||
@ -52,6 +57,8 @@ class PlaylistCard extends HookConsumerWidget {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
onPlaybuttonPressed: () async {
|
onPlaybuttonPressed: () async {
|
||||||
|
try {
|
||||||
|
updating.value = true;
|
||||||
if (isPlaylistPlaying && playing) {
|
if (isPlaylistPlaying && playing) {
|
||||||
return playlistNotifier.pause();
|
return playlistNotifier.pause();
|
||||||
} else if (isPlaylistPlaying && !playing) {
|
} else if (isPlaylistPlaying && !playing) {
|
||||||
@ -69,8 +76,13 @@ class PlaylistCard extends HookConsumerWidget {
|
|||||||
|
|
||||||
await playlistNotifier.loadAndPlay(fetchedTracks);
|
await playlistNotifier.loadAndPlay(fetchedTracks);
|
||||||
tracks.value = fetchedTracks;
|
tracks.value = fetchedTracks;
|
||||||
|
} finally {
|
||||||
|
updating.value = false;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onAddToQueuePressed: () async {
|
onAddToQueuePressed: () async {
|
||||||
|
updating.value = true;
|
||||||
|
try {
|
||||||
if (isPlaylistPlaying) return;
|
if (isPlaylistPlaying) return;
|
||||||
List<Track> fetchedTracks = await queryBowl.fetchQuery(
|
List<Track> fetchedTracks = await queryBowl.fetchQuery(
|
||||||
key: ValueKey(const Uuid().v4()),
|
key: ValueKey(const Uuid().v4()),
|
||||||
@ -88,6 +100,9 @@ class PlaylistCard extends HookConsumerWidget {
|
|||||||
content: Text("Added ${fetchedTracks.length} tracks to queue"),
|
content: Text("Added ${fetchedTracks.length} tracks to queue"),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
} finally {
|
||||||
|
updating.value = false;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ class PlaybuttonCard extends HookWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
final addToQueueButton = PlatformIconButton(
|
final addToQueueButton = PlatformIconButton(
|
||||||
onPressed: onAddToQueuePressed,
|
onPressed: isLoading ? null : onAddToQueuePressed,
|
||||||
backgroundColor:
|
backgroundColor:
|
||||||
PlatformTheme.of(context).secondaryBackgroundColor,
|
PlatformTheme.of(context).secondaryBackgroundColor,
|
||||||
hoverColor: PlatformTheme.of(context)
|
hoverColor: PlatformTheme.of(context)
|
||||||
|
Loading…
Reference in New Issue
Block a user