RhythmBox/lib/widgets/tracks/playlist_track_list.dart

47 lines
1.2 KiB
Dart
Raw Permalink Normal View History

2024-08-26 12:26:07 +00:00
import 'package:flutter/material.dart';
import 'package:get/get.dart';
2024-08-26 17:49:05 +00:00
import 'package:rhythm_box/providers/audio_player.dart';
2024-08-29 08:42:48 +00:00
import 'package:rhythm_box/widgets/tracks/track_tile.dart';
2024-08-26 12:26:07 +00:00
import 'package:skeletonizer/skeletonizer.dart';
import 'package:spotify/spotify.dart';
2024-08-29 08:42:48 +00:00
class PlaylistTrackList extends StatelessWidget {
2024-08-26 12:26:07 +00:00
final String playlistId;
2024-08-29 08:42:48 +00:00
final List<Track>? tracks;
2024-08-26 12:26:07 +00:00
2024-08-29 08:42:48 +00:00
final bool isLoading;
2024-08-26 12:26:07 +00:00
2024-08-29 08:42:48 +00:00
const PlaylistTrackList({
super.key,
this.isLoading = false,
required this.playlistId,
required this.tracks,
});
2024-08-26 12:26:07 +00:00
@override
Widget build(BuildContext context) {
return Skeletonizer.sliver(
2024-08-29 08:42:48 +00:00
enabled: isLoading,
2024-08-26 12:26:07 +00:00
child: SliverList.builder(
2024-08-29 08:42:48 +00:00
itemCount: tracks?.length ?? 3,
2024-08-26 12:26:07 +00:00
itemBuilder: (context, idx) {
2024-08-29 08:42:48 +00:00
final item = tracks?[idx];
return TrackTile(
item: item,
2024-08-26 17:49:05 +00:00
onTap: () {
if (item == null) return;
2024-08-28 12:34:35 +00:00
Get.find<AudioPlayerProvider>()
..load(
2024-08-29 08:42:48 +00:00
tracks!,
2024-08-28 12:34:35 +00:00
initialIndex: idx,
autoPlay: true,
)
2024-08-29 08:42:48 +00:00
..addCollection(playlistId);
2024-08-26 17:49:05 +00:00
},
2024-08-26 12:26:07 +00:00
);
},
),
);
}
}