Skip to content

Commit

Permalink
feat: show snackbar on adding playlist or tracks to queue
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Mar 7, 2023
1 parent 60ede5f commit 6bc1d32
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
27 changes: 19 additions & 8 deletions lib/components/album/album_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import 'package:fl_query_hooks/fl_query_hooks.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:platform_ui/platform_ui.dart';
import 'package:spotify/spotify.dart';
import 'package:spotube/components/shared/playbutton_card.dart';
import 'package:spotube/hooks/use_breakpoint_value.dart';
import 'package:spotube/provider/playlist_queue_provider.dart';
import 'package:spotube/provider/spotify_provider.dart';
import 'package:spotube/utils/service_utils.dart';
import 'package:spotube/utils/type_conversion_utils.dart';
import 'package:fluent_ui/fluent_ui.dart' as fluent;

enum AlbumType {
album,
Expand Down Expand Up @@ -108,21 +110,30 @@ class AlbumCard extends HookConsumerWidget {
.all()
.then((value) => value.toList());
},
).then(
(tracks) => tracks
?.map(
(e) => TypeConversionUtils.simpleTrack_X_Track(e, album))
.toList(),
);

if (fetchedTracks == null || fetchedTracks.isEmpty) return;

playlistNotifier.add(
fetchedTracks
.map((e) => TypeConversionUtils.simpleTrack_X_Track(e, album))
.toList(),
fetchedTracks,
);
tracks.value = fetchedTracks;
scaffold.showSnackBar(
SnackBar(
if (context.mounted) {
final snackbar = SnackBar(
content: Text("Added ${album.tracks?.length} tracks to queue"),
),
);
action: SnackBarAction(
label: "Undo",
onPressed: () {
playlistNotifier.remove(fetchedTracks);
},
),
);
ScaffoldMessenger.maybeOf(context)?.showSnackBar(snackbar);
}
} finally {
updating.value = false;
}
Expand Down
12 changes: 12 additions & 0 deletions lib/components/playlist/playlist_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ class PlaylistCard extends HookConsumerWidget {

playlistNotifier.add(fetchedTracks);
tracks.value = fetchedTracks;
if (context.mounted) {
final snackbar = SnackBar(
content: Text("Added ${tracks.value.length} tracks to queue"),
action: SnackBarAction(
label: "Undo",
onPressed: () {
playlistNotifier.remove(fetchedTracks);
},
),
);
ScaffoldMessenger.maybeOf(context)?.showSnackBar(snackbar);
}
} finally {
updating.value = false;
}
Expand Down

0 comments on commit 6bc1d32

Please sign in to comment.