Skip to content

Commit

Permalink
fix: search track play button isn't working
Browse files Browse the repository at this point in the history
feat: ask user to replace queue larger than 20 tracks and play
  • Loading branch information
KRTirtho committed Feb 10, 2023
1 parent d7eaa38 commit 0751f5e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 4 deletions.
49 changes: 49 additions & 0 deletions lib/components/shared/dialogs/prompt_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import 'package:flutter/cupertino.dart';
import 'package:platform_ui/platform_ui.dart';
import 'package:spotube/components/root/sidebar.dart';

Future<bool> showPromptDialog({
required BuildContext context,
required String title,
required String message,
String okText = "Ok",
String cancelText = "Cancel",
}) async {
return showPlatformAlertDialog<bool>(
context,
builder: (context) {
return PlatformAlertDialog(
title: PlatformText(title),
content: PlatformText(message),
macosAppIcon: Sidebar.brandLogo(),
primaryActions: [
if (platform == TargetPlatform.iOS)
CupertinoDialogAction(
isDefaultAction: true,
child: PlatformText(okText),
onPressed: () => Navigator.of(context).pop(true),
)
else
PlatformFilledButton(
child: PlatformText(okText),
onPressed: () => Navigator.of(context).pop(true),
),
],
secondaryActions: [
if (platform == TargetPlatform.iOS)
CupertinoDialogAction(
isDefaultAction: false,
child: PlatformText(cancelText),
onPressed: () => Navigator.of(context).pop(false),
)
else
PlatformFilledButton(
isSecondary: true,
onPressed: () => Navigator.of(context).pop(false),
child: PlatformText(cancelText),
),
],
);
},
).then((value) => value ?? false);
}
26 changes: 22 additions & 4 deletions lib/pages/search/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:platform_ui/platform_ui.dart';
import 'package:spotify/spotify.dart';
import 'package:spotube/collections/spotube_icons.dart';
import 'package:spotube/components/album/album_card.dart';
import 'package:spotube/components/shared/dialogs/prompt_dialog.dart';
import 'package:spotube/components/shared/shimmers/shimmer_playbutton_card.dart';
import 'package:spotube/components/shared/fallbacks/anonymous_fallback.dart';
import 'package:spotube/components/shared/page_window_title_bar.dart';
Expand Down Expand Up @@ -171,11 +172,28 @@ class SearchPage extends HookConsumerWidget {
onTrackPlayButtonPressed:
(currentTrack) async {
final isTrackPlaying =
playlist?.activeTrack.id !=
playlist?.activeTrack.id ==
currentTrack.id;
if (!isTrackPlaying) {
await playlistNotifier
.loadAndPlay([currentTrack]);
if (!isTrackPlaying &&
context.mounted) {
final shouldPlay =
(playlist?.tracks.length ?? 0) >
20
? await showPromptDialog(
context: context,
title:
"Playing ${currentTrack.name}",
message:
"This will clear the current queue. "
"${playlist?.tracks.length ?? 0} tracks will be removed\n"
"Do you want to continue?",
)
: true;

if (shouldPlay) {
await playlistNotifier
.loadAndPlay([currentTrack]);
}
}
},
);
Expand Down

0 comments on commit 0751f5e

Please sign in to comment.