mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-16 17:05:17 +00:00
fix: search track play button isn't working
feat: ask user to replace queue larger than 20 tracks and play
This commit is contained in:
parent
d7eaa38df7
commit
0751f5e317
49
lib/components/shared/dialogs/prompt_dialog.dart
Normal file
49
lib/components/shared/dialogs/prompt_dialog.dart
Normal file
@ -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);
|
||||||
|
}
|
@ -7,6 +7,7 @@ import 'package:platform_ui/platform_ui.dart';
|
|||||||
import 'package:spotify/spotify.dart';
|
import 'package:spotify/spotify.dart';
|
||||||
import 'package:spotube/collections/spotube_icons.dart';
|
import 'package:spotube/collections/spotube_icons.dart';
|
||||||
import 'package:spotube/components/album/album_card.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/shimmers/shimmer_playbutton_card.dart';
|
||||||
import 'package:spotube/components/shared/fallbacks/anonymous_fallback.dart';
|
import 'package:spotube/components/shared/fallbacks/anonymous_fallback.dart';
|
||||||
import 'package:spotube/components/shared/page_window_title_bar.dart';
|
import 'package:spotube/components/shared/page_window_title_bar.dart';
|
||||||
@ -171,12 +172,29 @@ class SearchPage extends HookConsumerWidget {
|
|||||||
onTrackPlayButtonPressed:
|
onTrackPlayButtonPressed:
|
||||||
(currentTrack) async {
|
(currentTrack) async {
|
||||||
final isTrackPlaying =
|
final isTrackPlaying =
|
||||||
playlist?.activeTrack.id !=
|
playlist?.activeTrack.id ==
|
||||||
currentTrack.id;
|
currentTrack.id;
|
||||||
if (!isTrackPlaying) {
|
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
|
await playlistNotifier
|
||||||
.loadAndPlay([currentTrack]);
|
.loadAndPlay([currentTrack]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
|
Loading…
Reference in New Issue
Block a user