Skip to content

Commit e9055f7

Browse files
authored
Merge pull request #88 from Kreedyy/master
Fix 'Create new playlist' button in 'currently playing' menu not adding the song into the created playlist
2 parents 5a51c86 + 1bf92b5 commit e9055f7

2 files changed

Lines changed: 31 additions & 11 deletions

File tree

lib/screens/now_playing_screen.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import '../l10n/app_localizations.dart';
1111
import '../models/song.dart';
1212
import '../models/radio_station.dart';
1313
import '../providers/player_provider.dart';
14+
import '../providers/library_provider.dart';
1415
import '../services/subsonic_service.dart';
1516
import '../services/player_ui_settings_service.dart';
1617
import '../widgets/star_rating_widget.dart';
@@ -1904,14 +1905,15 @@ class _SongInfoState extends State<_SongInfo> {
19041905
) async {
19051906
if (widget.song == null) return;
19061907

1907-
final subsonicService = Provider.of<SubsonicService>(
1908+
// Use LibraryProvider so the playlist list gets refreshed after creation
1909+
final libraryProvider = Provider.of<LibraryProvider>(
19081910
context,
19091911
listen: false,
19101912
);
19111913

19121914
try {
1913-
await subsonicService.createPlaylist(
1914-
name: playlistName,
1915+
await libraryProvider.createPlaylist(
1916+
playlistName,
19151917
songIds: [widget.song!.id],
19161918
);
19171919

lib/services/subsonic_service.dart

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -452,13 +452,32 @@ class SubsonicService {
452452
required String name,
453453
List<String>? songIds,
454454
}) async {
455-
final params = <String, String>{'name': name};
455+
// songId must be appended directly, using it as a map key would produce
456+
// songId[i]=x which Navidrome doesn't recognize
457+
String url = _buildUrl('createPlaylist', {'name': name});
456458
if (songIds != null && songIds.isNotEmpty) {
457-
for (int i = 0; i < songIds.length; i++) {
458-
params['songId[$i]'] = songIds[i];
459+
for (final songId in songIds) {
460+
url += '&songId=${Uri.encodeComponent(songId)}';
459461
}
460462
}
461-
await _request('createPlaylist', params);
463+
464+
try {
465+
final response = await _dio.get(url);
466+
final data = response.data;
467+
468+
final decoded = data is String ? json.decode(data) : data;
469+
final subsonicResponse = decoded['subsonic-response'];
470+
if (subsonicResponse == null) {
471+
throw Exception('Invalid response format');
472+
}
473+
474+
if (subsonicResponse['status'] != 'ok') {
475+
final error = subsonicResponse['error'];
476+
throw Exception(error?['message'] ?? 'Unknown error');
477+
}
478+
} on DioException catch (e) {
479+
throw Exception('Network error: ${e.message}');
480+
}
462481
}
463482

464483
Future<void> updatePlaylist({
@@ -486,15 +505,14 @@ class SubsonicService {
486505
}
487506
}
488507

489-
debugPrint('updatePlaylist URL: $url');
508+
debugPrint('updatePlaylist URL: ${_sanitizeUrl(url)}');
490509

491510
try {
492511
final response = await _dio.get(url);
493512
final data = response.data;
494513

495-
final subsonicResponse = data is String
496-
? json.decode(data)
497-
: data['subsonic-response'];
514+
final decoded = data is String ? json.decode(data) : data;
515+
final subsonicResponse = decoded['subsonic-response'];
498516
if (subsonicResponse == null) {
499517
throw Exception('Invalid response format');
500518
}

0 commit comments

Comments
 (0)