diff --git a/lib/components/shared/dialogs/prompt_dialog.dart b/lib/components/shared/dialogs/prompt_dialog.dart new file mode 100644 index 000000000..1bc4af920 --- /dev/null +++ b/lib/components/shared/dialogs/prompt_dialog.dart @@ -0,0 +1,49 @@ +import 'package:flutter/cupertino.dart'; +import 'package:platform_ui/platform_ui.dart'; +import 'package:spotube/components/root/sidebar.dart'; + +Future showPromptDialog({ + required BuildContext context, + required String title, + required String message, + String okText = "Ok", + String cancelText = "Cancel", +}) async { + return showPlatformAlertDialog( + 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); +} diff --git a/lib/pages/search/search.dart b/lib/pages/search/search.dart index 8e046f569..b2d38c08b 100644 --- a/lib/pages/search/search.dart +++ b/lib/pages/search/search.dart @@ -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'; @@ -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]); + } } }, );