Skip to content

Commit c61f495

Browse files
committed
refactor: clean up code formatting and improve dialog handling in playlist features
1 parent 6198cc4 commit c61f495

File tree

4 files changed

+30
-43
lines changed

4 files changed

+30
-43
lines changed

lib/screens/playlist_page.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ class _PlaylistPageState extends State<PlaylistPage> {
372372
onPressed: _handleSyncPlaylist,
373373
);
374374
}
375-
375+
376376
Widget _buildAddToPlaylistButton() {
377377
return IconButton.filledTonal(
378378
icon: const Icon(FluentIcons.album_add_24_regular),

lib/services/playlists_manager.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ String addSongsInCustomPlaylist(
213213
);
214214
return context.l10n!.addedSuccess;
215215
} else {
216-
return context.l10n!.songAlreadyInPlaylist; // Or some message saying all songs already exist
216+
return context.l10n!.songAlreadyInPlaylist;
217217
}
218218
} else {
219219
logger.log('Custom playlist not found for ytid: $playlistId');

lib/utilities/playlist_dialogs.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ import 'package:musify/services/playlists_manager.dart';
2626
import 'package:musify/utilities/flutter_toast.dart';
2727
import 'package:musify/utilities/playlist_image_picker.dart';
2828

29-
void showCreatePlaylistDialog(BuildContext context,
30-
{dynamic songToAdd, List<dynamic>? songsToAdd}) {
29+
void showCreatePlaylistDialog(
30+
BuildContext context, {
31+
dynamic songToAdd,
32+
List<dynamic>? songsToAdd,
33+
}) {
3134
var id = '';
3235
var customPlaylistName = '';
3336
var isYouTubeMode = songToAdd == null && songsToAdd == null;
@@ -381,12 +384,10 @@ void showAddToPlaylistDialog(
381384
),
382385
),
383386
actionsAlignment: MainAxisAlignment.end,
384-
actions: <Widget>[
387+
actions: [
385388
TextButton(
386389
child: Text(context.l10n!.cancel),
387-
onPressed: () {
388-
Navigator.of(context).pop();
389-
},
390+
onPressed: () => Navigator.pop(context),
390391
),
391392
FilledButton.icon(
392393
onPressed: () {

lib/widgets/playlist_bar.dart

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class PlaylistBar extends StatelessWidget {
195195
_handleEdit(context);
196196
break;
197197
case 'add_to_playlist':
198-
_handleAddPlaylistToPlaylist(context, colorScheme);
198+
_handleAddPlaylistToPlaylist(context);
199199
break;
200200
}
201201
},
@@ -422,56 +422,42 @@ class PlaylistBar extends StatelessWidget {
422422
}
423423
}
424424

425-
Future<void> _handleAddPlaylistToPlaylist(
426-
BuildContext context,
427-
ColorScheme colorScheme,
428-
) async {
425+
Future<void> _handleAddPlaylistToPlaylist(BuildContext context) async {
429426
if (_resolvedPlaylistId == null) {
430427
showToast(context, context.l10n!.error);
431428
return;
432429
}
433430

434-
final currentContext = NavigationManager().context;
431+
final navContext = NavigationManager().context;
435432
unawaited(
436433
showDialog(
437-
context: currentContext,
434+
context: navContext,
438435
barrierDismissible: false,
439-
builder: (BuildContext context) {
440-
return const Center(
441-
child: Spinner(),
442-
);
443-
},
436+
builder: (_) => const Center(child: Spinner()),
444437
),
445438
);
446439

447440
try {
448-
final fullPlaylist = await getPlaylistInfoForWidget(
449-
_resolvedPlaylistId!,
450-
);
441+
final fullPlaylist = await getPlaylistInfoForWidget(_resolvedPlaylistId);
442+
if (!navContext.mounted) return;
443+
Navigator.pop(navContext);
451444

452-
final appCtx = NavigationManager().context;
445+
if (fullPlaylist == null || fullPlaylist['list'] == null) {
446+
showToast(navContext, navContext.l10n!.error);
447+
return;
448+
}
453449

454-
if (appCtx.mounted) {
455-
Navigator.pop(appCtx); // close spinner
456-
if (fullPlaylist != null && fullPlaylist['list'] != null) {
457-
final List<dynamic> tracks = fullPlaylist['list'];
458-
if (tracks.isEmpty) {
459-
showToast(appCtx, appCtx.l10n!.noSongsInPlaylist);
460-
return;
461-
}
462-
unawaited(
463-
Future.microtask(
464-
() => showAddToPlaylistDialog(appCtx, songs: tracks)),
465-
);
466-
} else {
467-
showToast(appCtx, appCtx.l10n!.error);
468-
}
450+
final tracks = fullPlaylist['list'] as List<dynamic>;
451+
if (tracks.isEmpty) {
452+
showToast(navContext, navContext.l10n!.noSongsInPlaylist);
453+
return;
469454
}
455+
456+
showAddToPlaylistDialog(navContext, songs: tracks);
470457
} catch (e) {
471-
final appCtx = NavigationManager().context;
472-
if (appCtx.mounted) {
473-
Navigator.pop(appCtx); // close spinner
474-
showToast(appCtx, appCtx.l10n!.error);
458+
if (navContext.mounted) {
459+
Navigator.pop(navContext);
460+
showToast(navContext, navContext.l10n!.error);
475461
}
476462
}
477463
}

0 commit comments

Comments
 (0)